File size: 7,795 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | -- src/StarterGui/CraftingGUI.client.lua
-- Crafting panel showing recipes and resource counts, opened with C key
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local CraftingConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("CraftingConfig"))
local CraftEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("CraftEvent")
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "CraftingGUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")
local mainFrame = Instance.new("Frame")
mainFrame.Name = "CraftingFrame"
mainFrame.Size = UDim2.new(0, 380, 0, 420)
mainFrame.Position = UDim2.new(0.5, -190, 0.5, -210)
mainFrame.BackgroundColor3 = Color3.fromRGB(30, 25, 20)
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(180, 120, 50)
stroke.Thickness = 2
stroke.Parent = mainFrame
-- Title
local titleBar = Instance.new("Frame")
titleBar.Size = UDim2.new(1, 0, 0, 40)
titleBar.BackgroundColor3 = Color3.fromRGB(140, 90, 30)
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 = "Crafting Table"
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)
-- Resources bar
local resourceBar = Instance.new("Frame")
resourceBar.Size = UDim2.new(1, -20, 0, 30)
resourceBar.Position = UDim2.new(0, 10, 0, 45)
resourceBar.BackgroundColor3 = Color3.fromRGB(20, 18, 15)
resourceBar.BorderSizePixel = 0
resourceBar.Parent = mainFrame
local resourceCorner = Instance.new("UICorner")
resourceCorner.CornerRadius = UDim.new(0, 6)
resourceCorner.Parent = resourceBar
local resourceLabel = Instance.new("TextLabel")
resourceLabel.Name = "ResourceLabel"
resourceLabel.Size = UDim2.new(1, -10, 1, 0)
resourceLabel.Position = UDim2.new(0, 5, 0, 0)
resourceLabel.BackgroundTransparency = 1
resourceLabel.Text = "Wood: 0 | Stone: 0 | Gold: 0 | Diamond: 0"
resourceLabel.TextColor3 = Color3.fromRGB(200, 180, 140)
resourceLabel.TextScaled = true
resourceLabel.Font = Enum.Font.GothamMedium
resourceLabel.TextXAlignment = Enum.TextXAlignment.Left
resourceLabel.Parent = resourceBar
-- Recipe list
local scrollFrame = Instance.new("ScrollingFrame")
scrollFrame.Size = UDim2.new(1, -20, 1, -90)
scrollFrame.Position = UDim2.new(0, 10, 0, 80)
scrollFrame.BackgroundColor3 = Color3.fromRGB(18, 15, 12)
scrollFrame.BorderSizePixel = 0
scrollFrame.ScrollBarThickness = 5
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 listLayout = Instance.new("UIListLayout")
listLayout.SortOrder = Enum.SortOrder.LayoutOrder
listLayout.Padding = UDim.new(0, 6)
listLayout.Parent = scrollFrame
local scrollPad = Instance.new("UIPadding")
scrollPad.PaddingTop = UDim.new(0, 5)
scrollPad.PaddingLeft = UDim.new(0, 5)
scrollPad.PaddingRight = UDim.new(0, 5)
scrollPad.Parent = scrollFrame
local currentResources = {}
local function updateResourceDisplay()
local wood = currentResources.Wood or 0
local stone = currentResources.Stone or 0
local gold = currentResources.GoldOre or 0
local diamond = currentResources.Diamond or 0
resourceLabel.Text = "Wood: " .. wood .. " | Stone: " .. stone .. " | Gold: " .. gold .. " | Diamond: " .. diamond
end
local function populateRecipes()
for _, child in pairs(scrollFrame:GetChildren()) do
if child:IsA("Frame") then child:Destroy() end
end
local idx = 0
for recipeId, recipe in pairs(CraftingConfig.Recipes) do
idx = idx + 1
local card = Instance.new("Frame")
card.Name = recipeId
card.Size = UDim2.new(1, 0, 0, 80)
card.LayoutOrder = idx
card.BackgroundColor3 = Color3.fromRGB(40, 35, 28)
card.BorderSizePixel = 0
card.Parent = scrollFrame
local cardCorner = Instance.new("UICorner")
cardCorner.CornerRadius = UDim.new(0, 8)
cardCorner.Parent = card
-- Name
local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.new(0.6, 0, 0, 22)
nameLabel.Position = UDim2.new(0, 8, 0, 5)
nameLabel.BackgroundTransparency = 1
nameLabel.Text = recipe.Name
nameLabel.TextColor3 = Color3.fromRGB(255, 220, 150)
nameLabel.TextScaled = true
nameLabel.Font = Enum.Font.GothamBold
nameLabel.TextXAlignment = Enum.TextXAlignment.Left
nameLabel.Parent = card
-- Materials list
local matText = ""
for mat, amount in pairs(recipe.Materials) do
local have = currentResources[mat] or 0
local color = have >= amount and "OK" or "NEED"
matText = matText .. mat .. ": " .. have .. "/" .. amount .. " "
end
local matLabel = Instance.new("TextLabel")
matLabel.Name = "Materials"
matLabel.Size = UDim2.new(1, -16, 0, 20)
matLabel.Position = UDim2.new(0, 8, 0, 28)
matLabel.BackgroundTransparency = 1
matLabel.Text = matText
matLabel.TextColor3 = Color3.fromRGB(180, 170, 150)
matLabel.TextScaled = true
matLabel.Font = Enum.Font.Gotham
matLabel.TextXAlignment = Enum.TextXAlignment.Left
matLabel.Parent = card
-- Craft button
local craftBtn = Instance.new("TextButton")
craftBtn.Size = UDim2.new(0, 80, 0, 25)
craftBtn.Position = UDim2.new(1, -88, 1, -30)
craftBtn.BackgroundColor3 = Color3.fromRGB(140, 100, 30)
craftBtn.Text = "CRAFT"
craftBtn.TextColor3 = Color3.new(1, 1, 1)
craftBtn.TextScaled = true
craftBtn.Font = Enum.Font.GothamBold
craftBtn.Parent = card
local btnCorner = Instance.new("UICorner")
btnCorner.CornerRadius = UDim.new(0, 6)
btnCorner.Parent = craftBtn
craftBtn.MouseButton1Click:Connect(function()
CraftEvent:FireServer("Craft", recipeId)
end)
end
task.wait()
scrollFrame.CanvasSize = UDim2.new(0, 0, 0, listLayout.AbsoluteContentSize.Y + 15)
end
-- Listen for resource updates
CraftEvent.OnClientEvent:Connect(function(action, data)
if action == "ResourceUpdate" then
currentResources = data or {}
updateResourceDisplay()
populateRecipes()
end
end)
-- Toggle with C key
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.C then
mainFrame.Visible = not mainFrame.Visible
if mainFrame.Visible then
CraftEvent:FireServer("QueryResources")
end
end
end)
-- Initial populate
populateRecipes()
|