local function hitHumanoid(humanoid)
-- Check if humanoid already has "HitDeb"
if humanoid:FindFirstChild("HitDeb") == nil then
local new = Instance.new("BoolValue")
new.Name = "HitDeb"
new.Parent = humanoid
humanoid.Health -= 50
-- Wait for 0.1 seconds
wait(0.1)
-- Destroy "HitDeb"
new:Destroy()
end
end
-- Event handler for Touched event
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
-- Call hitHumanoid function in a new coroutine to avoid interference
spawn(function()
hitHumanoid(humanoid)
end)
end
end)
in this script, right after it damages the humanoid on the function, it fully stops the function in it’s entirety, I added prints and every print after the damage part doesn’t enter into the output, fix?
local function hitHumanoid(humanoid)
– Check if humanoid already has “HitDeb”
if humanoid:FindFirstChild(“HitDeb”) == nil then
local new = Instance.new(“BoolValue”)
new.Name = “HitDeb”
new.Parent = humanoid
humanoid.Health -= 50
-- Wait for 0.1 seconds
wait(0.1)
-- Destroy "HitDeb"
new:Destroy()
end
end
– Event handler for Touched event
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if humanoid then
– Call hitHumanoid function in a new coroutine to avoid interference
spawn(function()
hitHumanoid(humanoid)
end)
end
end)
Fixed, thank you tho!, here is the fixed script, keep in mind, the solution to a bug isn’t always bigger!
local cooldown = {} -- Table to store cooldowns for each humanoid
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
-- Get the current time
local currentTime = tick()
-- Check if the humanoid has a cooldown
if cooldown[humanoid] == nil or (currentTime - cooldown[humanoid] >= 0.1) then
-- Apply damage
humanoid.Health -= 50
-- Set the cooldown for this humanoid
cooldown[humanoid] = currentTime
end
end
end)