Hello, I am trying to implement a fire damage/affliction script in which on touch it does ticks for 4 seconds with initial damage and effects, which have been already implemented, however my debounce is ineffective due to the fact that my for i loop, serving as the tick, affects the function indirectly by waiting 4 seconds (for i = 1,5). I do not know how to approach this and am eager for feedback/support on this topic. I initially tried to initiate/reenable another script from within the initial script, but that did not work. My code and examples are below, I appreciate any help
-- --SETINGS
local dmg = 14
local db = false
local CD = .2
local ticks = 6
local isFire = false
--VARIABLES
local model = script.Parent
local Bleed = script.Parent.Particle
local ClonedParticle = Bleed:Clone()
local Bleed2 = script.Parent.Blood
local UI = game.StarterGui.Vignette.Overlay
local BleedClone = Bleed2:Clone()
local f = script.Parent.Parent.Sounds
local Anim = script.Parent.Animation -- Animation
local Anim2 = script.Parent.Return
--local players = game:GetService("Players")
--local player = players.LocalPlayer
--SOUNDS/TABLES
local fire = f.Fire
local Scream0 = f.Scream0
local Scream1 = f.Scream1
local Scream2 = f.Scream2
local Scream3 = f.Scream3
local tables = {Scream0,Scream1,Scream2,Scream3}
script.Parent.Touched:Connect(function(Hit)
if not db then
db = true
if not db then return end
print('played')
fire:Play()
if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")then
local test=Hit.Parent.Humanoid:LoadAnimation(script.Parent.Animation)
test:Play()
if Hit.Parent.Humanoid.Health >= 40 then --checks hp for scream validity
Scream0:Play()
else
Scream0.Playing = false
end
Hit.Parent.Humanoid.Health = (Hit.Parent.Humanoid.Health - dmg) -- initial damage
BleedClone:Clone()
BleedClone.Enabled = true
BleedClone.Parent = Hit.Parent.Torso
ClonedParticle:Clone()
ClonedParticle.Enabled = true
ClonedParticle.Parent = Hit.Parent.Torso
if db == true then
Hit.Parent.Humanoid.WalkSpeed = Hit.Parent.Humanoid.WalkSpeed + 1.5
for i = 1,5 do --tick damage, gotta fix delay!
task.wait(.8)
Hit.Parent.Humanoid.Health = (Hit.Parent.Humanoid.Health - math.random(6,8))
end
BleedClone.Enabled = false
ClonedParticle.Enabled = false
task.wait(CD)
db=false
test:Stop()
local test2=Hit.Parent.Humanoid:LoadAnimation(script.Parent.Return)
test2:Play()
if db == false then
Hit.Parent.Humanoid.WalkSpeed = Hit.Parent.Humanoid.WalkSpeed - 1.5
fire.Playing = false
--task.wait(1)
--test2:Stop()
end
end
end
end
end)
https://gyazo.com/49c4e21ae004d0901f43607f84535cb4
https://gyazo.com/d84aae46649b0c3f3d6f0951aee92ade < example of problem