Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cookie Clicker ?

Asked by 7 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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?

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. User#11440 120 — 7y
0
Yes im tryign to find leaderstats then inside the leaderstats is Money johndeer2233 439 — 7y
0
I fixed it johndeer2233 439 — 7y

2 answers

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

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)
Ad
Log in to vote
-1
Answered by
k1nq 30
7 years ago

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.

Answer this question