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

My currency rewarding script gives previous player money instead of you, anyone know a fix?

Asked by
Nump4d 5
4 years ago
function OnClick()

    local players = game.Players:GetPlayers()
    for i=1,#players do
        if (players[i]:FindFirstChild("leaderstats") ~= nil) then
            local clicks = players[i]:FindFirstChild("leaderstats")["ParkBucks"]
            if (clicks ~= nil)  then
                script.Parent.ClickDetector.MaxActivationDistance = 0
                script.Parent.Transparency = 1
                clicks.Value = clicks.Value + 10
                script.Parent.Sound:Play()
                wait(20)    
                script.Parent.ClickDetector.MaxActivationDistance = 10
                script.Parent.Transparency = 0

            end

            end
        end
    end

script.Parent.ClickDetector.MouseClick:connect(OnClick)

I do not know what is wrong with my script, when it regenerates it gives the previous player that clicked it the money instead of the "clicker". Any help will be greatly appreciated.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Instead of looping through game.Players, you can use the player parameter of MouseClick

script.Parent.MouseClick:Connect(function(playerWhoClicked)
    local leaderstats = playerWhoClicked:FindFirstChild("leaderstats")
    if leaderstats then
        local clicks = leaderstats.Clicks

        script.Parent.ClickDetector.MaxActivationDistance = 0
        script.Parent.Transparency = 1
        clicks.Value = clicks.Value + 10
        script.Parent.Sound:Play()

        wait(20) 

        script.Parent.ClickDetector.MaxActivationDistance = 10
        script.Parent.Transparency = 0
    end
end)
0
This does not work Nump4d 5 — 4y
0
what doesnt work about it? royaltoe 5144 — 4y
Ad

Answer this question