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

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

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)

1 comment

0

wait()

3 answers

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

1 comment

0

yields the entire thread

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)

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!

1 comment

0

I'm not the one who asked the question but why use this? Doesn't wait() do the same thing?

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