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

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

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

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)

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