The following script is for a laser beam that damages the player on touch.
debounce = false
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
end
wait(0.5)
debounce = false
end
end)
Now this debounce applies for everyone, not just the player who touched the laser beam. I’ve thought of making an array for the debounce but I don’t know how to proceed.
local debounces = { }
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if debounces[player] then
return -- If their debounce is still active then return
end
debounces[player] = true
player.Character.Humanoid:TakeDamage(20)
wait(0.5)
debounces[player] = nil
end)