So I have a folder named "KillBricks". And many parts in there. And I created this script:
local Folder = script.Parent
for i,part in pairs(Folder:GetChildren()) do
if part:IsA('BasePart') then
part.Touched:connect(function(poc)
if not poc.Parent then return end
if not poc.Parent:FindFirstChild('Humanoid') then return end
local hum = poc.Parent.Humanoid
hum.Health = 0
print('Damaging Player')
end)
end
end
As you can see. Everytime the player touches the Kill Brick. It will kill the player.
But at the print() function. It will print many many times. Making the performance get worse.
But if I add a debounce to it like this:
local Folder = script.Parent
for i,part in pairs(Folder:GetChildren()) do
if part:IsA('BasePart') then
local debounce = false
part.Touched:connect(function(poc)
if not debounce then
if not poc.Parent then return end
if not poc.Parent:FindFirstChild('Humanoid') then return end
debounce = true
local hum = poc.Parent.Humanoid
hum.Health = 0
print('The player has been killed')
wait(3)
debounce = false
end
end)
end
end
Then It wouldn't work as expected:
The part would print many times. But less than the other script. (Depending on the server's response speed adding the debounce.)
It would give the opportunity for other players to jump on the Kill Brick without dying for 3 seconds.
So how do you make a filter for each of the Humanoid in the Touched event?
Edit: One thing I should mention that is:
A repro on the devforum: https://devforum.roblox.com/t/repro-touched-events-delayed/38118
If you turn it into a Local Script. Taking one of the Local character's parts and fire the server to take the request. It will work BUT if there's any exploit that deletes the LocalScript itself then the players should've been god already.

2 comments
Theres a topic about this at the end of the wiki: http://wiki.roblox.com/index.php?title=Debounce
@xEiffel Clearly you didn't read the whole question didn't you? And It even say obviously "only allow the player to be hurt by the part every 3 seconds"