Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
Ad

Answer this question