Script ignores the delay I placed, calling the function to work instantly

I have been trying to make a delay between damage but for some reason it (almost) instantly kills the player, ignoring the delay.

Anything to replace? Something im missing? let me know

local lavadelay = script.parent.lavasettings.lavadmgdelay.value
local lavadmg = script.parent.lavasettings.lavadmgdelay.value
local function BurnPlayer(otherPart) --detects part touched
	local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")--detects if part touched is a player part
	while otherPart do
		wait(lavadelay)
		otherPart.Parent.Humanoid:TakeDamage(lavadmg)
		wait(lavadelay)
	end
end

Are you sure that lavadelay is a NumberValue?

1 Like

Yes, the value of that is 0.5.

If your damage isn’t 100 then I think the problem is you’re calling this function every time the part is touched > so that means the while loop would be overlapping I would think. Try taking out the loop and just adding a set value for damage > then adding a variable and checking the variable on and off with the delay time.

1 Like

That function gets called every time the player touches the part. wait() yields the current thread x amount of seconds, it doesn’t prevent the same function from running again. What you want is a debounce.

1 Like

I am so bad at debounce, it crashed roblox studio when I tried this tutorial for the first time