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

how do i make the clone delete after waiting a little?

Asked by 3 years ago

how do i make the clone delete after waiting a little

game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local ragdollV3 = script.RagdollV3:Clone() ragdollV3.Parent = character ragdollV3.Disabled = false end) end)

0
wait() greatneil80 2647 — 3y

3 answers

Log in to vote
0
Answered by
CodeWon 181
3 years ago

You could simply use 2 common built in functions, wait() and :Destroy():

wait() -- Put the amount of time you want the script to wait forin the parenthesis
ragdollV3:Destroy() -- :Destroy() completly removes the object from the game
0
yields the entire thread iuclds 720 — 3y
Ad
Log in to vote
0
Answered by
iuclds 720 Moderation Voter
3 years ago
game.Players.PlayerAdded:connect(function(player)        
      player.CharacterAdded:connect(function(character)
            local ragdollV3 = script.RagdollV3:Clone()
            ragdollV3.Parent = character
            ragdollV3.Disabled = false
        coroutine.wrap(function()
           wait(time) -- your time
           ragdollV3:Destroy()
        end)() -- () is used for calling the coroutine
        -- coroutines basically run code without stopping the entire thread. it's useful but there's a stack trace issue
      end)
end)
Log in to vote
-1
Answered by 3 years ago
Edited 3 years ago

Hello! You can use the Debris Service!!! Here's how it goes:

Debris has a function called AddItem. The first argument is the object to be removed and the second is the how long does Debris have to wait before removing the object.

Debris:AddItem(<item>, <lifetime>)

When applied to your script:

local Debris = game:GetService("Debris")

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character) 
        local ragdollV3 = script.RagdollV3:Clone()
        ragdollV3.Parent = character
        ragdollV3.Disabled = false

        Debris:AddItem(ragdollV3, 3) --ragdollV3 will be removed after 3 seconds
    end)
end)

I hope this helps!

0
I'm not the one who asked the question but why use this? Doesn't wait() do the same thing? CodeWon 181 — 3y

Answer this question