Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

You would have to use Debris

local Debris = game:GetService("Debris")

Debris:AddItem(YourPart, NumberOfSecondsUntilRemoval)

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 Hemitheos 0 — 3y
Ad

Answer this question