How can i do this with cloning objects

so i want to clone a sphere every second and destroy each clone every maybe 10 seconds or so. how would i achieve this?

local ball = script.Parent.BallDuper

while true do
	local clone = ball:Clone()
	clone.CFrame = ball.CFrame
	clone.Parent = ball.Parent
	clone.CanCollide = true
	clone.Transparency = 0
	clone.Anchored = false
	wait(1)
	clone:Destroy()
end

by the way, i know that this destroys the sphere after 1 second. i just have this to show what my script looks like

@woloexe What I would do is have a spawning script that spawns to the Workspace (or wherever you would want them) from ReplicatedStorage. You then have a script in the clone that says repeat wait() until script.Parent.Parent==Workspace and then wait(10) script.Parent:Destroy()

Spawning Script:

while wait(timeYouWant) do
local sphere = game.ReplicatedStorage.Sphere:Clone()
sphere.Parent = game.Workspace

Sphere Script:

repeat wait() until script.Parent.Parent = game.Workspace
wait(timeYouWant)
script.Parent:Destroy()
1 Like

Its a good idea, to have scripts inside those clones? Or maybe use just 1 module script for all clones?

I would go with the module script instead of placing a script inside each clone.

1 Like

@Dev_Peashie that may be a better way I’ve never used ModuleScripts and that seemed pretty simple.

1 Like

you can use debris to destroy clone every 10 second. This is example

local Part = workspace.Part --This is example
local Debris = game:GetService("Debris") --Getting debris service, it allows you to destroy item
--Just like destroy method, except it will not pauses the script before part get destroyed

while wait(1) do --Execute code below every 1 second
    local CloneBall = Part:Clone() --Clone the ball
    --Properties goes here
    CloneBall.Parent = workspace --Parent it to the workspace
    Debris:AddItem(CloneBall,10) --Add item to destroy without pausing the script
end

i have added explanation in case if you dont understand @woloexe

2 Likes