File size: 6,344 Bytes
0712d5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | -- src/StarterGui/InventoryGUI.client.lua
-- Grid-based inventory display with tool equip buttons
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local ShopConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ShopConfig"))
local EquipToolEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("EquipToolEvent")
local ShopEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ShopEvent")
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "InventoryGUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")
local mainFrame = Instance.new("Frame")
mainFrame.Name = "InventoryFrame"
mainFrame.Size = UDim2.new(0, 400, 0, 350)
mainFrame.Position = UDim2.new(0.5, -200, 0.5, -175)
mainFrame.BackgroundColor3 = Color3.fromRGB(25, 28, 35)
mainFrame.BackgroundTransparency = 0.05
mainFrame.BorderSizePixel = 0
mainFrame.Visible = false
mainFrame.Parent = screenGui
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 12)
corner.Parent = mainFrame
local stroke = Instance.new("UIStroke")
stroke.Color = Color3.fromRGB(100, 130, 200)
stroke.Thickness = 2
stroke.Parent = mainFrame
-- Title
local titleBar = Instance.new("Frame")
titleBar.Size = UDim2.new(1, 0, 0, 40)
titleBar.BackgroundColor3 = Color3.fromRGB(50, 70, 120)
titleBar.BorderSizePixel = 0
titleBar.Parent = mainFrame
local titleCorner = Instance.new("UICorner")
titleCorner.CornerRadius = UDim.new(0, 12)
titleCorner.Parent = titleBar
local titleLabel = Instance.new("TextLabel")
titleLabel.Size = UDim2.new(1, -50, 1, 0)
titleLabel.Position = UDim2.new(0, 15, 0, 0)
titleLabel.BackgroundTransparency = 1
titleLabel.Text = "Inventory"
titleLabel.TextColor3 = Color3.new(1, 1, 1)
titleLabel.TextScaled = true
titleLabel.Font = Enum.Font.GothamBold
titleLabel.TextXAlignment = Enum.TextXAlignment.Left
titleLabel.Parent = titleBar
local closeBtn = Instance.new("TextButton")
closeBtn.Size = UDim2.new(0, 30, 0, 30)
closeBtn.Position = UDim2.new(1, -35, 0, 5)
closeBtn.BackgroundColor3 = Color3.fromRGB(180, 50, 50)
closeBtn.Text = "X"
closeBtn.TextColor3 = Color3.new(1, 1, 1)
closeBtn.TextScaled = true
closeBtn.Font = Enum.Font.GothamBold
closeBtn.Parent = titleBar
local closeCorner = Instance.new("UICorner")
closeCorner.CornerRadius = UDim.new(0, 6)
closeCorner.Parent = closeBtn
closeBtn.MouseButton1Click:Connect(function()
mainFrame.Visible = false
end)
-- Scroll frame for items
local scrollFrame = Instance.new("ScrollingFrame")
scrollFrame.Size = UDim2.new(1, -20, 1, -55)
scrollFrame.Position = UDim2.new(0, 10, 0, 45)
scrollFrame.BackgroundColor3 = Color3.fromRGB(15, 18, 22)
scrollFrame.BorderSizePixel = 0
scrollFrame.ScrollBarThickness = 6
scrollFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
scrollFrame.Parent = mainFrame
local scrollCorner = Instance.new("UICorner")
scrollCorner.CornerRadius = UDim.new(0, 8)
scrollCorner.Parent = scrollFrame
local gridLayout = Instance.new("UIGridLayout")
gridLayout.CellSize = UDim2.new(0, 110, 0, 70)
gridLayout.CellPadding = UDim2.new(0, 8, 0, 8)
gridLayout.SortOrder = Enum.SortOrder.LayoutOrder
gridLayout.Parent = scrollFrame
local padding = Instance.new("UIPadding")
padding.PaddingTop = UDim.new(0, 5)
padding.PaddingLeft = UDim.new(0, 5)
padding.Parent = scrollFrame
-- Cache current inventory
local currentInventory = nil
local function refreshInventory(inventory)
currentInventory = inventory
for _, child in pairs(scrollFrame:GetChildren()) do
if child:IsA("Frame") then child:Destroy() end
end
if not inventory then return end
local idx = 0
for category, items in pairs(inventory) do
for _, itemId in ipairs(items) do
idx = idx + 1
local itemData = ShopConfig.Items[itemId]
local itemName = itemData and itemData.Name or itemId
local card = Instance.new("Frame")
card.Name = itemId .. "_" .. idx
card.LayoutOrder = idx
card.BackgroundColor3 = Color3.fromRGB(40, 45, 55)
card.BorderSizePixel = 0
card.Parent = scrollFrame
local cardCorner = Instance.new("UICorner")
cardCorner.CornerRadius = UDim.new(0, 6)
cardCorner.Parent = card
local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.new(1, -6, 0, 22)
nameLabel.Position = UDim2.new(0, 3, 0, 3)
nameLabel.BackgroundTransparency = 1
nameLabel.Text = itemName
nameLabel.TextColor3 = Color3.new(1, 1, 1)
nameLabel.TextScaled = true
nameLabel.Font = Enum.Font.GothamBold
nameLabel.Parent = card
local typeLabel = Instance.new("TextLabel")
typeLabel.Size = UDim2.new(1, -6, 0, 15)
typeLabel.Position = UDim2.new(0, 3, 0, 25)
typeLabel.BackgroundTransparency = 1
typeLabel.Text = category
typeLabel.TextColor3 = Color3.fromRGB(150, 150, 180)
typeLabel.TextScaled = true
typeLabel.Font = Enum.Font.Gotham
typeLabel.Parent = card
-- Equip button (only for tools)
if category == "Tools" then
local equipBtn = Instance.new("TextButton")
equipBtn.Size = UDim2.new(0.8, 0, 0, 20)
equipBtn.Position = UDim2.new(0.1, 0, 1, -23)
equipBtn.BackgroundColor3 = Color3.fromRGB(60, 120, 200)
equipBtn.Text = "Equip"
equipBtn.TextColor3 = Color3.new(1, 1, 1)
equipBtn.TextScaled = true
equipBtn.Font = Enum.Font.GothamBold
equipBtn.Parent = card
local eqCorner = Instance.new("UICorner")
eqCorner.CornerRadius = UDim.new(0, 4)
eqCorner.Parent = equipBtn
equipBtn.MouseButton1Click:Connect(function()
EquipToolEvent:FireServer(itemId)
end)
end
end
end
task.wait()
scrollFrame.CanvasSize = UDim2.new(0, 0, 0, gridLayout.AbsoluteContentSize.Y + 15)
end
-- Listen for inventory updates from server
ShopEvent.OnClientEvent:Connect(function(action, data)
if action == "InventoryUpdate" then
refreshInventory(data)
end
end)
-- Toggle with I key
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.I then
mainFrame.Visible = not mainFrame.Visible
end
end)
|