#How to fix coroutine spam over touched event?

2 messages · Page 1 of 1 (latest)

fast hollow
#
explosion.Touched:Connect(function(hit)
                if not debounce and hit.Parent.Parent == workspace.Enemies then
                    debounce = true
                    hit.Parent:FindFirstChild("Humanoid"):TakeDamage(stats.ExplosionDamage)
                    if target:FindFirstChild("Humanoid") and target:FindFirstChild("HumanoidRootPart") then
                        coroutine.wrap(function()
                            if hit.Parent.Parent == workspace.Enemies  then
                                while task.wait(stats.BleedCoolDown) do
                                    print("test")
                                    hit.Parent.Humanoid:TakeDamage(stats.BleedDamage)
                                end
                            end
                        end)()
                    end
                end
            end)```
for some reason the coroutine is just spamming multiple times without waiting the bleed tick or cooldown. There's no error
bitter mist