Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cookie Clicker ?

I feel stupid on this one please don't downvote have not scripted in a long time why do I have an error

player = script.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function(PlayerWhoClicked)
	local gui = game.Players.LocalPlayer.PlayerGui.CookieMain.ClickMe
	local leader = game.Players.LocalPlayer:WaitForChild("leaderstats")
	if leader then
		local Money = game.Players.LocalPlayer.leader:WaitForChild("Money")
		if Money then
			Money.Value = Money.Value + 1
		end

	end

end)

error = leader is not a valid member of Player?

3 comments

0

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.

0

Yes im tryign to find leaderstats then inside the leaderstats is Money

0

I fixed it

2 answers

✓ Accepted answer

Several things are wrong here.

  1. :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.

  2. 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

  3. 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)

I mean, it's pretty clear, if there error is player.leader doesn't exist, then it's just that, you haven't made the leaderstats yet.

This discussion is preserved as it was. New answers, comments, and votes are closed.