local Players = game:GetService("Players") local UserInputService =…
- User
local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService")
local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui")
-- Create ScreenGui local screenGui = Instance.new("ScreenGui") screenGui.Name = "MinecraftStyleInventory" screenGui.Parent = playerGui screenGui.Enabled = false
-- Main frame (bigger and darker) local mainFrame = Instance.new("Frame") mainFrame.Size = UDim2.new(0, 700, 0, 450) mainFrame.Position = UDim2.new(0.5, -350, 0.4, -225) mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30) mainFrame.BorderSizePixel = 0 mainFrame.Parent = screenGui
local uICorner = Instance.new("UICorner") uICorner.CornerRadius = UDim.new(0, 15) uICorner.Parent = mainFrame
-- ViewportFrame (left side) for character display local viewport = Instance.new("ViewportFrame") viewport.Size = UDim2.new(0, 280, 0, 420) viewport.Position = UDim2.new(0, 10, 0, 15) viewport.BackgroundColor3 = Color3.fromRGB(60, 60, 60) viewport.BorderSizePixel = 0 viewport.Parent = mainFrame
local vpCorner = Instance.new("UICorner") vpCorner.CornerRadius = UDim.new(0, 12) vpCorner.Parent = viewport
-- Crafting grid 2x2 (top right) local craftingFrame = Instance.new("Frame") craftingFrame.Size = UDim2.new(0, 200, 0, 200) craftingFrame.Position = UDim2.new(0, 310, 0, 15) craftingFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50) craftingFrame.BorderSizePixel = 0 craftingFrame.Parent = mainFrame
local craftCorner = Instance.new("UICorner") craftCorner.CornerRadius = UDim.new(0, 10) craftCorner.Parent = craftingFrame
local craftingGrid = Instance.new("UIGridLayout") craftingGrid.CellSize = UDim2.new(0, 90, 0, 90) craftingGrid.CellPadding = UDim2.new(0, 10, 0, 10) craftingGrid.FillDirection = Enum.FillDirection.Horizontal craftingGrid.Parent = craftingFrame
-- Create 4 crafting slots (empty frames) local craftingSlots = {} for i=1,4 do local slot = Instance.new("Frame") slot.Name = "CraftSlot"..i slot.BackgroundColor3 = Color3.fromRGB(80, 80, 80) slot.BorderSizePixel = 2 slot.BorderColor3 = Color3.fromRGB(150, 150, 150) slot.Parent = craftingFrame
local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 6) corner.Parent = slot -- Placeholder text label local label = Instance.new("TextLabel") label.Text = "" label.BackgroundTransparency = 1 label.Size = UDim2.new(1, 0, 1, 0) label.TextColor3 = Color3.new(1, 1, 1) label.Font = Enum.Font.SourceSansBold label.TextScaled = true label.Parent = slot craftingSlots[i] = slotend
-- Inventory frame (bottom right) local inventoryFrame = Instance.new("Frame") inventoryFrame.Size = UDim2.new(0, 380, 0, 210) inventoryFrame.Position = UDim2.new(0, 310, 0, 230) inventoryFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50) inventoryFrame.BorderSizePixel = 0 inventoryFrame.Parent = mainFrame
local invCorner = Instance.new("UICorner") invCorner.CornerRadius = UDim.new(0, 12) invCorner.Parent = inventoryFrame
local inventoryGrid = Instance.new("UIGridLayout") inventoryGrid.CellSize = UDim2.new(0, 80, 0, 50) inventoryGrid.CellPadding = UDim2.new(0, 10, 0, 10) inventoryGrid.FillDirection = Enum.FillDirection.Horizontal inventoryGrid.Parent = inventoryFrame
-- Equipped tool display local equippedFrame = Instance.new("Frame") equippedFrame.Size = UDim2.new(0, 680, 0, 40) equippedFrame.Position = UDim2.new(0, 10, 0, 400) equippedFrame.BackgroundColor3 = Color3.fromRGB(70, 70, 30) equippedFrame.BorderSizePixel = 2 equippedFrame.BorderColor3 = Color3.fromRGB(255, 255, 120) equippedFrame.Parent = mainFrame
local equippedLabel = Instance.new("TextLabel") equippedLabel.Size = UDim2.new(1, 0, 1, 0) equippedLabel.BackgroundTransparency = 1 equippedLabel.Text = "Equipped Tool: None" equippedLabel.TextColor3 = Color3.new(1, 1, 1) equippedLabel.Font = Enum.Font.SourceSansBold equippedLabel.TextScaled = true equippedLabel.Parent = equippedFrame
-- Helper: setup viewport to show player character local function setupViewport() if not player.Character then return end viewport:ClearAllChildren()
local charClone = player.Character:Clone() -- Make parts anchored & remove Motor6D for static pose for _, part in ipairs(charClone:GetDescendants()) do if part:IsA("BasePart") then part.Anchored = true part.CanCollide = false elseif part:IsA("Motor6D") then part:Destroy() end end local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChildWhichIsA("BasePart") if rootPart then local offset = rootPart.CFrame for _, part in ipairs(charClone:GetDescendants()) do if part:IsA("BasePart") then part.CFrame = part.CFrame - offset.p end end end charClone.Parent = viewport -- Lighting for character local light = Instance.new("PointLight") light.Brightness = 2 light.Range = 15 light.Parent = rootPart -- Setup camera to look at character nicely local camera = Instance.new("Camera") viewport.CurrentCamera = camera camera.Parent = viewport camera.CFrame = CFrame.new(Vector3.new(0, 2, 5), Vector3.new(0, 1, 0))end
-- Refresh inventory: show tools in backpack as buttons local function refreshInventory() print("Refreshing inventory...") -- Clear previous buttons for _, child in ipairs(inventoryFrame:GetChildren()) do if child:IsA("TextButton") then child:Destroy() end end
inventoryGrid.Parent = inventoryFrame for _, tool in ipairs(player.Backpack:GetChildren()) do print("Found tool:", tool.Name) if tool:IsA("Tool") then local btn = Instance.new("TextButton") btn.Size = UDim2.new(0, 80, 0, 50) btn.BackgroundColor3 = Color3.fromRGB(90, 90, 90) btn.BorderSizePixel = 0 btn.TextColor3 = Color3.new(1,1,1) btn.Font = Enum.Font.SourceSansBold btn.TextScaled = true btn.Text = tool.Name btn.Parent = inventoryFrame btn.MouseButton1Click:Connect(function() equippedLabel.Text = "Equipped Tool: " .. tool.Name if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then player.Character.Humanoid:EquipTool(tool) end end) end end -- Show equipped tool if player.Character then for _, child in ipairs(player.Character:GetChildren()) do if child:IsA("Tool") then equippedLabel.Text = "Equipped Tool: " .. child.Name end end end print("Inventory refreshed.")end
-- Toggle GUI with E key UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.E then screenGui.Enabled = not screenGui.Enabled if screenGui.Enabled then setupViewport() refreshInventory() end end end)
-- Update inventory when tools change player.Backpack.ChildAdded:Connect(refreshInventory) player.Backpack.ChildRemoved:Connect(refreshInventory)
player.CharacterAdded:Connect(function(char) char.ChildAdded:Connect(function(child) if child:IsA("Tool") then refreshInventory() end end) char.ChildRemoved:Connect(function(child) if child:IsA("Tool") then refreshInventory() end end) refreshInventory() end)
if player.Character then refreshInventory() end
-- Initial refresh if GUI already enabled (usually off) if screenGui.Enabled then setupViewport() end
can you fix the viewport it not showing the character i try it to 10 days and it not working
Assistant
Fixing the Viewport Character Display
The issue with your viewport not showing the character is likely due to several factors. Here's a fixed version of your
setupViewport()function with explanations:local function setupViewport() -- Wait for character to exist if not player.Character then player.CharacterAdded:Wait() end viewport:ClearAllChildren() -- Create a camera for the viewport local camera = Instance.new("Camera") viewport.CurrentCamera = camera camera.Parent = viewport -- Clone the character local charClone = player.Character:Clone() -- Make parts anchored & remove scripts/Motor6D for _, part in ipairs(charClone:GetDescendants()) do if part:IsA("BasePart") then part.Anchored = true part.CanCollide = false elseif part:IsA("Motor6D") or part:IsA("Script") or part:IsA("LocalScript") then part:Destroy() end end -- Position the character in the viewport local humanoidRootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChildWhichIsA("BasePart") if humanoidRootPart then -- Center the character humanoidRootPart.CFrame = CFrame.new() -- Add lighting local light = Instance.new("PointLight") light.Brightness = 1.5 light.Range = 15 light.Parent = humanoidRootPart -- Position the camera camera.CFrame = CFrame.new(Vector3.new(0, 2, 5), Vector3.new(0, 1, 0)) end -- Parent the character clone to the viewport charClone.Parent = viewport -- Force a render update task.wait() viewport:GetPropertyChangedSignal("CurrentCamera"):Wait() endKey Fixes:
-
Added waiting for character: Ensures the character exists before trying to clone it.
-
Removed scripts: Destroyed all scripts in the clone to prevent any potential issues.
-
Proper camera setup: Created and assigned the camera before parenting the character.
-
Simplified positioning: Just set the root part to CFrame.new() (origin) rather than trying to calculate offsets.
-
Forced render update: Added waits to ensure the viewport updates properly.
-
Lighting adjustment: Reduced brightness slightly for better visibility.
Additional Recommendations:
-
Viewport size: Make sure your viewport is large enough (280x420 should be fine).
-
Character scale: If your character appears too small or large, adjust the camera position:
-- Move camera closer/farther camera.CFrame = CFrame.new(Vector3.new(0, 2, 3), Vector3.new(0, 1, 0)) -- Closer camera.CFrame = CFrame.new(Vector3.new(0, 2, 8), Vector3.new(0, 1, 0)) -- Farther -
Character rotation: If you want the character to face a different direction:
humanoidRootPart.CFrame = CFrame.Angles(0, math.rad(180), 0) -- Face away from camera -
Error handling: Consider adding error handling around the character cloning process.
This should now properly display your character in the viewport when you press E to open the inventory. If you're still having issues, check the Output window for any error messages that might indicate other problems.
-
- User
ful script
Assistant
Complete Fixed Minecraft-Style Inventory Script
Here's the complete fixed script with all the viewport issues resolved and additional improvements:
local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") -- Create ScreenGui local screenGui = Instance.new("ScreenGui") screenGui.Name = "MinecraftStyleInventory" screenGui.Parent = playerGui screenGui.Enabled = false screenGui.ResetOnSpawn = false -- Main frame (bigger and darker) local mainFrame = Instance.new("Frame") mainFrame.Size = UDim2.new(0, 700, 0, 450) mainFrame.Position = UDim2.new(0.5, -350, 0.4, -225) mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30) mainFrame.BorderSizePixel = 0 mainFrame.Parent = screenGui local uICorner = Instance.new("UICorner") uICorner.CornerRadius = UDim.new(0, 15) uICorner.Parent = mainFrame -- ViewportFrame (left side) for character display local viewport = Instance.new("ViewportFrame") viewport.Size = UDim2.new(0, 280, 0, 420) viewport.Position = UDim2.new(0, 10, 0, 15) viewport.BackgroundColor3 = Color3.fromRGB(60, 60, 60) viewport.BorderSizePixel = 0 viewport.Parent = mainFrame local vpCorner = Instance.new("UICorner") vpCorner.CornerRadius = UDim.new(0, 12) vpCorner.Parent = viewport -- Crafting grid 2x2 (top right) local craftingFrame = Instance.new("Frame") craftingFrame.Size = UDim2.new(0, 200, 0, 200) craftingFrame.Position = UDim2.new(0, 310, 0, 15) craftingFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50) craftingFrame.BorderSizePixel = 0 craftingFrame.Parent = mainFrame local craftCorner = Instance.new("UICorner") craftCorner.CornerRadius = UDim.new(0, 10) craftCorner.Parent = craftingFrame local craftingGrid = Instance.new("UIGridLayout") craftingGrid.CellSize = UDim2.new(0, 90, 0, 90) craftingGrid.CellPadding = UDim2.new(0, 10, 0, 10) craftingGrid.FillDirection = Enum.FillDirection.Horizontal craftingGrid.Parent = craftingFrame -- Create 4 crafting slots (empty frames) local craftingSlots = {} for i=1,4 do local slot = Instance.new("Frame") slot.Name = "CraftSlot"..i slot.BackgroundColor3 = Color3.fromRGB(80, 80, 80) slot.BorderSizePixel = 2 slot.BorderColor3 = Color3.fromRGB(150, 150, 150) slot.Parent = craftingFrame local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 6) corner.Parent = slot -- Placeholder text label local label = Instance.new("TextLabel") label.Text = "" label.BackgroundTransparency = 1 label.Size = UDim2.new(1, 0, 1, 0) label.TextColor3 = Color3.new(1, 1, 1) label.Font = Enum.Font.SourceSansBold label.TextScaled = true label.Parent = slot craftingSlots[i] = slot end -- Inventory frame (bottom right) local inventoryFrame = Instance.new("Frame") inventoryFrame.Size = UDim2.new(0, 380, 0, 210) inventoryFrame.Position = UDim2.new(0, 310, 0, 230) inventoryFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50) inventoryFrame.BorderSizePixel = 0 inventoryFrame.Parent = mainFrame local invCorner = Instance.new("UICorner") invCorner.CornerRadius = UDim.new(0, 12) invCorner.Parent = inventoryFrame local inventoryGrid = Instance.new("UIGridLayout") inventoryGrid.CellSize = UDim2.new(0, 80, 0, 50) inventoryGrid.CellPadding = UDim2.new(0, 10, 0, 10) inventoryGrid.FillDirection = Enum.FillDirection.Horizontal inventoryGrid.Parent = inventoryFrame -- Equipped tool display local equippedFrame = Instance.new("Frame") equippedFrame.Size = UDim2.new(0, 680, 0, 40) equippedFrame.Position = UDim2.new(0, 10, 0, 400) equippedFrame.BackgroundColor3 = Color3.fromRGB(70, 70, 30) equippedFrame.BorderSizePixel = 2 equippedFrame.BorderColor3 = Color3.fromRGB(255, 255, 120) equippedFrame.Parent = mainFrame local equippedLabel = Instance.new("TextLabel") equippedLabel.Size = UDim2.new(1, 0, 1, 0) equippedLabel.BackgroundTransparency = 1 equippedLabel.Text = "Equipped Tool: None" equippedLabel.TextColor3 = Color3.new(1, 1, 1) equippedLabel.Font = Enum.Font.SourceSansBold equippedLabel.TextScaled = true equippedLabel.Parent = equippedFrame -- Helper: setup viewport to show player character local function setupViewport() -- Wait for character to exist if not player.Character then player.CharacterAdded:Wait() end viewport:ClearAllChildren() -- Create a camera for the viewport local camera = Instance.new("Camera") viewport.CurrentCamera = camera camera.Parent = viewport -- Clone the character local charClone = player.Character:Clone() -- Make parts anchored & remove scripts/Motor6D for _, part in ipairs(charClone:GetDescendants()) do if part:IsA("BasePart") then part.Anchored = true part.CanCollide = false elseif part:IsA("Motor6D") or part:IsA("Script") or part:IsA("LocalScript") then part:Destroy() end end -- Position the character in the viewport local humanoidRootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChildWhichIsA("BasePart") if humanoidRootPart then -- Center the character humanoidRootPart.CFrame = CFrame.new() -- Add lighting local light = Instance.new("PointLight") light.Brightness = 1.5 light.Range = 15 light.Parent = humanoidRootPart -- Position the camera camera.CFrame = CFrame.new(Vector3.new(0, 2, 5), Vector3.new(0, 1, 0)) -- Rotate character to face camera humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, math.pi, 0) end -- Parent the character clone to the viewport charClone.Parent = viewport -- Force a render update task.wait() viewport:GetPropertyChangedSignal("CurrentCamera"):Wait() end -- Refresh inventory: show tools in backpack as buttons local function refreshInventory() -- Clear previous buttons for _, child in ipairs(inventoryFrame:GetChildren()) do if child:IsA("TextButton") then child:Destroy() end end inventoryGrid.Parent = inventoryFrame for _, tool in ipairs(player.Backpack:GetChildren()) do if tool:IsA("Tool") then local btn = Instance.new("TextButton") btn.Size = UDim2.new(0, 80, 0, 50) btn.BackgroundColor3 = Color3.fromRGB(90, 90, 90) btn.BorderSizePixel = 0 btn.TextColor3 = Color3.new(1,1,1) btn.Font = Enum.Font.SourceSansBold btn.TextScaled = true btn.Text = tool.Name btn.Parent = inventoryFrame btn.MouseButton1Click:Connect(function() equippedLabel.Text = "Equipped Tool: " .. tool.Name if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then player.Character.Humanoid:EquipTool
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.