Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I create a despawn timer without using "wait" at all?

So basically I am modifying a gear which fires the cloneDagger projectile. I added a line where it despawns at a certain velocity, however I want it to have to be travelling at this velocity for 3 seconds before it despawns, rather than doing it as soon as it reaches that velocity.

However, these daggers follow the player constantly in order to return back to the player, so using the "wait" function interrupts this process and they stop following the player since it pauses the whole script.

function returnToCharacter(cloneDagger)
	if cloneDagger and myTorso then 
		local distance = (cloneDagger.Position - myTorso.Position).magnitude
		local lookAt = (myTorso.Position - cloneDagger.Position).unit
		while distance > 4.0 and cloneDagger do 
			cloneDagger.Velocity = lookAt * distance			
			
			if cloneDagger.Velocity.Magnitude < 18 and cloneDagger.Velocity.Magnitude > 12 then
				for fade = 0, 1, 0.1 do
					cloneDagger.Transparency = cloneDagger.Transparency + 0.1
					wait(0.1)
				end
				cloneDagger:Remove()
				cloneDagger = nil
			end
			
			if cloneDagger then 
				lookAt = (myTorso.Position - cloneDagger.Position).unit 
				distance = (myTorso.Position - cloneDagger.Position).magnitude
								
			end
			

1 answer

You would have to use Debris

local Debris = game:GetService("Debris")

Debris:AddItem(YourPart, NumberOfSecondsUntilRemoval)

1 comment

0

Thank you, that is helpful. However this will still always remove it 3 seconds after it has reached the despawn velocity, regardless of whether or not it exited the despawn velocity. I want it so it has to be at that velocity for 3 seconds until it's removed at all

This discussion is preserved as it was. New answers, comments, and votes are closed.