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

How to make debounce activate for individual player and not server?

^ It always doesn't that wether I'm working on a GUI or a onTouch Brick. Help?!

1 answer

A dictionary is a pretty simple way.

Instead of using a straight up debounce variable, use something like debounce[playername]:

local cantTouchUntil = {}
-- A dictionary of times of when they are allowed to touch something

function myEvent( player )
	-- Somehow, given player (maybe we have to finesse it from
	-- parameter.Parent or something)
	local canTouch = (cantTouchUntil[player] or 0) <= tick()
	if canTouch then
		cantTouchUntil[player] = tick() + 5 -- Debounce for 5 seconds
		-- Now do whatever else
	end
end

Or, with a more standard debounce approach:

local disabled = {}

function myEvent(player)
	if not disabled[player] then
		disabled[player] = true
		-- Do whatever else
		wait(5)
		disabled[player] = false
	end
end

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