local debounce = false local player = game.Players.LocalPlayer function ButtonPress() if debounce == false then debounce = true -- PUT THE THING YOU WANT TO HAPPEN v player.leaderstats.Money.Value = player.leaderstats.Money.Value + 10 wait(3) debounce = false end end script.Parent.ClickDetector.MouseClick:connect(ButtonPress)
i want it to give money ween clicking but only every 3 seconds why did this not work?
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!