Im working on a shop GUI and im just one error away from completing it. it keeps saying "attempt to index upvalue 'tool' (a nil value)". How do I fix it? here's my script attempt :
local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats:FindFirstChild("Money").Value >= price.Value then
player.leaderstats:FindFirstChild("Money").Value = player.leaderstats:FindFirstChild("Money").Value - price.Value
local clone = tool:Clone()
clone.Parent = player.Backpack
local clone2 = tool:Clone()
clone2.Parent = player.StarterGear
end
end)

2 comments
WaitForChild isn't always the fix. The objects are already there.
what do you mean "code"?