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

Why does this subtract points from all players, and not only the one that presses it?

Asked by 10 years ago

When you click the button, it's supposed to subtract points from the player that clicks it, but instead it subtracts points from all players in the server?

~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~game.Players.PlayerAdded:connect(function(player) function onClicked() if 1+1==2 then wait(.4) player.leaderstats["Maple Leaves"].Value = player.leaderstats["Maple Leaves"].Value - 10 game.Workspace.tv1.Decal.Transparency=0 script.Parent.Name=("Now Watching..") wait(300) game.Workspace.tv1.Decal.Transparency=1 script.Parent.Name=("Watch Pay Per View (10)")

    end
    end

script.Parent.ClickDetector.MouseClick:connect(onClicked) end)

    ~~~~

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

You are subtracting from the leaderstats of what ever the variable player is. The variable player in your case is every player that enters the game. What you should do is utilize the argument playerWhoClicked of the MouseClick event:

script.Parent.ClickDetector.MouseClick:connect(function(clicked) -- clicked is the player who clicked it
    clicked.leaderstats["Maple Leaves"].Value = clicked.leaderstats["Maple Leaves"].Value - 10
    game.Workspace.tv1.Decal.Transparency=0 
    script.Parent.Name=("Now Watching..") 
    wait(300)   
    game.Workspace.tv1.Decal.Transparency=1 
    script.Parent.Name=("Watch Pay Per View (10)")
end)
Ad

Answer this question