Delay function not working when character dies?

I have a module that handles bullet shooting/collisions, however this delay function does not fire if the player dies before hand? to my knowledge, the delay function should still run regardless.

print("BULLET HIT")
delay(8, function()
	print("RETURN")
	SplatterCache:ReturnPart(SplatterBullet)
end)


It has definately been more than 8 seconds after the BULLET HIT prints.

In case anyone asks if theres anything going on between these 2 prints, there isn’t.
image

Also worth noting, this delay function does work and the print does print if you are still alive after this 8 seconds. It’s only if you die.

Is it possible that this script is getting deleted when the player respawns?

No. It’s a module script stored under repstorage

Which script is requiring and using that module? Is it local?

Ye. To my knowledge the modules functions should still run though? Once required and functions fired they don’t disconnect??

In my own tests, if the Local Script is terminated before the length of the Module Script’s delay() is reached, then delay() will not go on to spawn another thread.

I don’t understand exactly why that happens. Hope someone can follow up with more technical details.

1 Like

Oh, right :confused:

Is there a work around I can use then??

Keeping the Local Scripts outside of ScreenGuis that have ResetOnSpawn turned on will make sure they don’t get caught in the crossfire.

From what I’ve seen when you require a module you’re basically cloning all the code inside the script who required it, specifically in a dictionary, that means if the requiring script gets destroyed the module will lose the connection and so stop the delays, the waits etc… A solution would be to let a localscript that handles the general graphics and effects inside PlayerScripts manage that, either passing the part trough an event or moving the whole script to it.

2 Likes

The local script is inside a model that gets cloned to inside the character