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

How do i not share stats?

Asked by
viison -5
8 years ago

Currently i made a new script for my cookie clicker game and i don't understand, when im clicking on the cookie with the script all the players in the server gets a cookie? How do i make it a certain player who clicks it gets the cookie?

debounce = false

function onClick(Player)
    if not debounce then
        debounce = true
            for _,Player in pairs(game.Players:GetPlayers()) do
            if Player:findFirstChild("leaderstats") then
            Player.leaderstats.Cookies.Value = Player.leaderstats.Cookies.Value +1
            wait(0.1)
            debounce = false

            end
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)
0
Is this in a LocalScript? User#9949 0 — 8y
0
nope viison -5 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Your problem is that for _,Player means for every player. So what you are essentially doing is saying that for every player in the game, you want to increase their Cookies value by 1

Here is the solution it should work:

debounce = false

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if not debounce then
        debounce = true
        local playerName = game.Players:WaitForChild(Player.Name)
            if playerName:findFirstChild("leaderstats") then
            playerName.leaderstats.Cookies.Value = playerName.leaderstats.Cookies.Value +1
            wait(0.1)
            debounce = false
        end
    end
end)

If it doesn't work, please comment and I will fix whatever is wrong.

Ad

Answer this question