I am very new at scripting. What is wrong with this?
`
19:59:26.815 - Players.Play_MazeOfHeck.PlayerGui.ScreenGui.Shop.Stats.Frame.LongStick.Buy.Buy:3: attempt to index nil with ‘WaitForChild’
`
local Cost = 100
local playerStats = player:WaitForChild("leaderstats")
local playerGold = playerStats:WaitForChild("Gold")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local Owned = gui.Shop.Stats.Frame.LongStick.Owned.Value
script.Parent.MouseButton1Click:Connect(function()
if playerGold.Value >= Cost and Owned.Value == false then
playerGold.Value = playerGold.Value - Cost
Owned.Value = true
end
end)
I think you might’ve cut off your player variable by accident when posting your code. One unfortunate mistake I see in a lot of beginners is that they try to call the LocalPlayer in a server Script. It is only possible to call LocalPlayer from a LocalScript, make sure you did not fall for this.
Also after you get past this error you will need to remove the .Value on this: local Owned = gui.Shop.Stats.Frame.LongStick.Owned.Value
because you can not change a value from that, it will just give you the value at the time it was defined.