#Goal:# My goal is to make a damage system that damages people with a DEBOUNCE. I have a folder of Bandits and want to make sure if any of the bandits touches an enemy they get damaged. I want to avoid loops as much as possible.
#Script (This is a part):#
--// Variables \\--
local RunService = game:GetService("RunService")
local Settings = require(game:GetService("ReplicatedStorage").ModuleScripts.SETTINGS)
local Respawn_Time = Settings.BANDIT.RESPAWN_TIME
local plrServ = game:GetService('Players')
local NPCBackup = game:GetService('ServerStorage').NPCBackup.Bandit
local function DamageEnemy(NPC, h, Damage)
h.Parent.Humanoid:TakeDamage(Damage)
end
local function TouchFunction(Bandit)
local Debounce = true
local DamageAmount = Settings.BANDIT.DAMAGE
Bandit.Touched:Connect(function(h)
if Debounce and h.Parent.Name ~= Bandit.Parent.Name and h.Parent:FindFirstChild('Humanoid') then
Debounce = false
DamageEnemy(Bandit, h, DamageAmount)
wait(2)
Debounce = true
end
end)
end
for _, Bandit in pairs(workspace.Bandits:GetDescendants()) do
if Bandit:IsA('BasePart') then
spawn(function() TouchFunction(Bandit) end)
end
end
Anyway,
#Error:# There is no real error but for some reason when I die, everything stops working. The PROBLEM is the DEBOUNCE doesn't work.
Basically: Everything works in terms of damaging but it seems like the Debounce has no effect.
Evidence: https://gyazo.com/267466299848731ce7e2209f03d6eb4f ~ In studio https://gyazo.com/7af3ca54c0c7782f3018a2d431993fb3 ~ In actual Server
I appreciate and thank you if you provide any helpful feedback on how to solve this issue or how to improve the code in general.
Thank you for reading.

8 comments
Could you give a bit more information about what you're trying to do and what kind of script you're using?
I'm trying to make a claim button when you hatch a egg and click claim the element will go into players inventory
What line in the code you posted I sent the error on?
Line 34, so basically the if statement
what the hell kind of script is this?!
Damage script
Server script
Put the debounce outside of function. On the code that is triggers, put
if debounce then return end. Then, immediately change the debounce boolean type. Try this.