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
You would have to use Debris
local Debris = game:GetService("Debris")
Debris:AddItem(YourPart, NumberOfSecondsUntilRemoval)