✓ Accepted answer
Several things are wrong here.
:WaitForChild can't return nil. It just keeps waiting and waiting until it finds something. So the if leader and if Money checks are pointless.
You define the local variable leader, but then you don't use it. You say game.Players.LocalPlayer.leader, but the object is called leaderstats, not leader
You don't use player anywhere in the script... Since this must be a localscript (since you're using LocalPlayer) why not just use game.Players.LocalPlayer? In that case, only the local player is going to be able to trigger the neven anyway (and PlayerWhoClicked was bogus anyway)
With those mistakes fixed,
player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
local gui = player.PlayerGui.CookieMain.ClickMe
local leader = player:WaitForChild("leaderstats")
local Money = leader:WaitForChild("Money")
Money.Value = Money.Value + 1
end)
Really it doesn't make too much sense to be doing the waiting inside of the function, either, since you'll probably want those values elsewhere. Of course, you should also be waiting for the PlayerGui and CookieMain, probably.
player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("CookieMain").ClickMe
local leader = player:WaitForChild("leaderstats")
local Money = leader:WaitForChild("Money")
script.Parent.MouseButton1Click:connect(function()
Money.Value = Money.Value + 1
end)
3 comments
On line 7, did you mean leaderstats? Because you put leader. I think you were trying to use the variable but that's not how you're suppose to do it.
Yes im tryign to find leaderstats then inside the leaderstats is Money
I fixed it