Using a wait in a Heartbeat function acts weird

I am currently trying to remake the “In Search Of Corpses” ability that the Smile item from Item Asylum has. (Yes i am aware it doesn’t originate from IA)

The way it works, Is it has a hitbox that slowly damages any players in it.

i have a good hitbox system, When a player enters the box, they are added to a list, of already hit characters, and when its stopped, that list has all its hit characters removed.
(it uses a Heartbeat function to cast the hitbox and stuff)

So in the heartbeat function, I added a task.wait, and after that wait it removes all the characters from the list, It works, But very oddly (sorry for the horrible video):

What i tried was wrapping it in a task.spawn (so it wouldnt affect anything else)
Like so:

task.spawn(function()
	task.wait(0.3)
	AlreadyHitParts = {}
end)

It works better, still odd (damages humanoids twice inconsistently) But i dont think having a task.spawn being created every heartbeat is a very good idea…

Any help is appreciated!

1 Like

Using Heartbeat is in this case not optimal. I recommend to use an other type of loop.

1 Like

I cant use anything else that isnt a Heartbeat/RenderStepped, the loop must be a function like those due to the way my game is set up

Bumping because i still haven’t fixed this.

(also, how do i check if a table has a certain method/function?)

Maybe if ur making a new task.spawn before the cooldown finishes then when it finishes another one of ur task.spawn functions will end the cooldown again