Hello. I am trying to make a localized debounce on a server sided script. For example: There are 2 players, Badcc and Asimo. Let’s say Asimo touches a block that prints a message in the output, he’s not able to print that message for another 5 seconds after touching the block. But Badcc can come along and print the message, but he has to wait 5 seconds to do it again, also. Hopefully that makes sense.
So how would I go about doing that? Thanks in advance .
1 Like
What I would do is: store who pressed it in a table and then delete their name after 5 seconds, if they touch it again and their name is still stored then it doesnt work for them, but if their name is gone you can make the script work . Sorry if I’m overly complicating things.
4 Likes
Yep the table debounce technique.
Here is how it looks in code form.
local debounceTable = {}
part.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and not debounceTable[player] then
debounceTable[player] = player --make the if statement false
wait(5)
debounceTable[player] = nil
end
end)
12 Likes