Skip to content
The Chat Archive
gpt-4.1-mini-2025-04-14· OpenAI LMArena Human Preference 140K

local Players = game:GetService("Players") local UserInputService =…

  1. 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] = 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() 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

  2. Assistant

    Certainly! The issue with the viewport not showing the character is often related to how the character model is cloned and positioned inside the ViewportFrame. Your code is mostly correct, but there are a few common pitfalls and improvements that can help fix the problem:

    Common issues with ViewportFrame character display:

    1. Camera setup: The camera must be parented to the ViewportFrame and positioned correctly.
    2. Character positioning: The character parts must be positioned relative to the camera so they are visible.
    3. Lighting: The ViewportFrame needs lighting to properly render the model.
    4. Anchoring and Motor6D removal: You did this correctly, but make sure the character is centered properly.

    Here's a fixed and improved version of your setupViewport function:

    local function setupViewport()
    	if not player.Character then return end
    	viewport:ClearAllChildren()
    
    	local charClone = player.Character:Clone()
    
    	-- Remove Motor6D and anchor parts
    	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
    
    	-- Center the character at origin (0,0,0)
    	local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChildWhichIsA("BasePart")
    	if rootPart then
    		local offset = rootPart.CFrame.Position
    		for _, part in ipairs(charClone:GetDescendants()) do
    			if part:IsA("BasePart") then
    				part.CFrame = part.CFrame - offset
    			end
    		end
    	end
    
    	charClone.Parent = viewport
    
    	-- Setup lighting for the viewport
    	local light = Instance.new("DirectionalLight")
    	light.Parent = viewport
    	light.Brightness = 2
    	light.Shadows = true
    	light.Direction = Vector3.new(-1, -1, -1)
    
    	-- Setup camera
    	local camera = Instance.new("Camera")
    	camera.Parent = viewport
    	viewport.CurrentCamera = camera
    
    	-- Position the camera to look at the character
    	camera.CFrame = CFrame.new(Vector3.new(0, 2, 5), Vector3.new(0, 1, 0))
    end
    

    Explanation of changes:

    • Lighting: Changed from PointLight on the root part to a DirectionalLight parented to the viewport. This is more reliable for viewport lighting.
    • Camera: Make sure the camera is parented to the viewport and assigned to viewport.CurrentCamera.
    • Positioning: The character is centered at the origin by subtracting the root part's position from all parts.
    • Anchoring: Parts are anchored and collisions disabled to prevent physics issues.

    Additional tips:

    • Make sure your character has a HumanoidRootPart or at least some BasePart to center on.
    • You can adjust the camera position (Vector3.new(0, 2, 5)) and lookAt point (Vector3.new(0, 1, 0)) to better frame the character.
    • If your character has accessories or hats, they should clone and display correctly with this setup.

    If you want, I can help you integrate this fixed function into your full script or troubleshoot further! Just let me know.

  3. User

    ful script

  4. Assistant

    Certainly! Here's your full script with the fixed and improved setupViewport function integrated, along with some minor cleanups and comments for clarity:

    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] = 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()
    	if not player.Character then return end
    	viewport:ClearAllChildren()
    
    	local charClone = player.Character:Clone()
    
    	-- Remove Motor6D and anchor parts
    	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
    
    	-- Center the character at origin (0,0,0)
    	local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChildWhichIsA("BasePart")
    	if rootPart then
    		local offset = rootPart.CFrame.Position
    		for _, part in ipairs(charClone:GetDescendants()) do
    			if part:IsA("BasePart") then
    				part.CFrame = part.CFrame - offset
    			end
    		end
    	end
    
    	charClone.Parent = viewport
    
    	-- Setup lighting for the viewport
    	local light = Instance.new("DirectionalLight")
    	light.Parent = viewport
    	light.Brightness = 2
    	light.Shadows = true
    	light.Direction = Vector3.new(-1, -1, -1)
    
    	-- Setup camera
    	local camera = Instance.new("Camera")
    	camera.Parent = viewport
    	viewport.CurrentCamera = camera
    
    	-- Position the camera to look at the character
    	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()
    	-- 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(tool)
    				end
    			end)
    		end
    	end
    
    	-- Show equipped tool
    	if player.Character then
    		local equippedTool = nil
    		for _, child in ipairs(player.Character:GetChildren()) do
    			if child:IsA("Tool") then
    				equippedTool = child
    				break
    			end
    		end
    		if equippedTool then
    			equippedLabel.Text = "Equipped Tool: " .. equippedTool.Name
    		else
    			equippedLabel.Text = "Equipped Tool: None"
    		end
    	end
    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
    

    How to use:

    • Press E to toggle the inventory GUI.
    • The left side viewport will show your character model.
    • The top right is a 2x2 crafting grid (empty for now).
    • The bottom right shows your backpack tools as buttons.
    • Clicking a tool button equips it and updates the equipped tool label.

    If you want me to help you add actual crafting functionality or improve the UI further, just ask!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.