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

How could I put a debounce into this script?

script.Parent.ClickDetector.MouseClick:connect(function(player)
	local players = game.Players:FindFirstChild(player.Name)
			local clicks = players:FindFirstChild("leaderstats")["XP"]
				clicks.Value = clicks.Value + 1
			end)

4 comments

0

A debounce is used to stop a function from firing too many times in quick succession. A click detector will only fire once per click, so a debounce would do nothing. Are you wanting a player to only be able to fire it once?

0

I have the same question with vector3_zero, but you can just stop the debounce by doing debounce = false, and back them again using debounce = true! But, also, I'll leave a message to the moderator, please don't close this question by no descriptived. The title is already self-explanatory. Thank you.

0

ClickDetector.MouseClick is not the kind of event that would invoke numerous signals per second. BasePart.Touched is most commonly used with debounces because it has said potential.

0

Ah I see. I want the player to only be able to push the button once every so often so it can't be spam clicked.

1 answer

✓ Accepted answer

Those types of scripts don't require usually a debounce, but in case you want to prevent the player from spamming the button, you can try this:

local cooldown = false

script.Parent.ClickDetector.MouseClick:connect(function(player)
	if not cooldown then
		cooldown = true
		local players = game.Players:FindFirstChild(player.Name)
		local clicks = players:FindFirstChild("leaderstats")["XP"]
		clicks.Value = clicks.Value + 1
		wait(1) -- Change this to your wish
		cooldown = false
	end
end)

1 comment

0

Thank you!

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