✓ Accepted answer
This is because the script you are using is located in the workspace, under a part. Also it is because the script you are using is probably a Local Script.
If you're going to use a Server Script located under the part, you're going to need to do this:
local debounce = false
script.Parent.ClickDetector.MouseClick:connect(function(plr)
if debounce == false then
print(plr.Name)
debounce = true
plr.leaderstats.Legend.Value = plr.leaderstats.Legend.Value + 10
wait(3)
debounce = false
end
end)
Explanation:
Whenever you do something or run a function triggered by a player, the first parameter is always the player Pretty sure...might need a vouch on that. Parameters are the things that go inside the parenthesis "()" in code. I think of them as a different kind of variables, which they kinda are.
The player that it gets is the player located in game.Players so there is no need for the line local player = game.Players.LocalPlayers, it also isn't a LocalScript so that wouldn't work at all. Place this script in a ServerScript and put it under the part.
This script should work and I explained what you were doing wrong so if you'd please accept, that'd be awesome!
1 comment
Because LocalPlayer does not work in ServerScripts. ClickDetector will provide you with the player who clicked on the brick, use that to define player.