So I have a sword tool and everytime the player clicks they receive coins. Is there a way to make it so the clicks do not spam and I can have a downtime. More specfically I’m asking is there a way to make it so that the player can not spam click, and the player can only click and get coins every second or so. Heres the clicking script.
local touched
script.Parent.Activated:Connect(function()
if not touched then touched = true
workspace.MainEvent.AddCoins:FireServer()
wait(3) -- cooldown
touched = false
end)
A debounce mechanism.
Try using ReplicatedStorage for containing Remotes, seems better organized.
You would have to change the clicking script a bit. This should work.
local cooldown = false
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
game.Workspace.MainEvent.AddCoins:FireServer()
wait (1) -- Change this to the amount you want the cooldown length to be.
cooldown = false
end
end)
What this is doing is basically when the player clicks, It checks if cooldown is equal to false. If it is, It will set it to true, Add the coins, and wait a second before it goes back to false so it works again.