How to use debris while cloning an object from ServerStorage?

Hello,

I want to make a remake of Dodge The Teapots of Doom game, and I need to clone a part and delete it after 10 seconds using Debris. In which I can’t seem to do.

I’ve done a while true do loop, then adding it waiting 10 seconds and deleting it, but it doesn’t keep repeating, since I need it to repeat WHILE its repeating. I’ve tried doing Debris but I guess I can’t set the parent of something when using Debris.

Here’s my script when I use debris:

local kettle = game.ServerStorage:WaitForChild("EvilKettle")

local debris = game:GetService("Debris")

while true do
	wait(1)
	local EvilKettle = kettle:Clone()
	
	EvilKettle.Anchored = false
	EvilKettle.CanCollide = true
	EvilKettle.CFrame = script.Parent.CFrame
	
	wait(4)
	
	debris:AddItem(EvilKettle, 10)
end

I was thinking of using coroutine but I am not entirely sure if I should use it yet. I will wait for replies and see.

Anything helps.

And yes, I forgot to set the parent to workspace. Fixed it though.

If you want to delete if after 10 seconds, why is there a 4-second wait?

1 Like

It was for testing purposes. Just so it goes by faster

Edit:

Nevermind, I added a coroutine and fixed it. This is how I did it:

local kettle = game.ServerStorage:WaitForChild("EvilKettle")

local debris = game:GetService("Debris")

while true do
	local EvilKettle = kettle:Clone()
	
	local newThread = coroutine.create(function()
		while true do
			wait(10)
			EvilKettle:Destroy()
		end
	end)
	
	coroutine.resume(newThread)
	EvilKettle.Parent = game.Workspace
	EvilKettle.Anchored = false
	EvilKettle.CanCollide = true
	EvilKettle.CFrame = script.Parent.CFrame
	wait(5)
end