Hello , I wanted to make a script that deletes parts then it places them back with a clone

Hello , with this script im trying to make it so it destroys the parts then replaces them back with a clone from lighting but everytime its says an error , I have tried other ways to make it work but still it doesn’t want to

while true do

game.Workspace.Part1:Destroy()

game.Workspace.Part2:Destroy()

print(“11”)

wait(1)

game.Lighting.Part1:clone().Parent = game.Workspace

game.Lighting.Part2:clone().Parent = game.Workspace

print(“22”)

wait(3)

game.Workspace.Part1:Destroy()

game.Workspace.Part2:Destroy()

print(“33”)

end

the error :
image

2 Likes

Im not very good with scripting but maybe try putting the parts in replicatedstorage?

2 Likes

Let me format it for you.

while true do

game.Workspace.Part1:Destroy()

game.Workspace.Part2:Destroy()

print(“11”)

wait(1)

game.Lighting.Part1:clone().Parent = game.Workspace

game.Lighting.Part2:clone().Parent = game.Workspace

print(“22”)

wait(3)

game.Workspace.Part1:Destroy()

game.Workspace.Part2:Destroy()

print(“33”)

end
1 Like

Make the clone a variable.

local Clone = game.Lighting.Part1:Clone()
Clone.Parent = game.Workspace

wait(1)

Clone:Destroy()

Try:
local part1 = game.Lighting.Part1:clone()
part1.Parent = blahblah
part1.Position = blahblah
part1.Size = blahblah
etc.

What language you formatted it in? It isn’t lua. Isn’t it python syntax highlight?

local current1 = game.Lighting:WaitForChild("Part1")
local current2 = game.Lighting:WaitForChild("Part2")
    
while true do
    local oneClone = current1:Clone()
    oneClone.Parent = workspace

    local twoClone = current2:Clone()
    twoClone.Parent = workspace

    wait(1)

    oneClone:Destroy()
    twoClone:Destroy()

    wait(1)
end

Your script attempts to delete them before they’re destroyed due to the loop. I’ve made a tidier version for you.

the cloning works , but when it tries to delete it , it doesn’t

There isn’t even anything named inside Part1 inside the workspace…?

It should look something like this:

local Part1 = game.Lighting.Part1
local Part2 = game.Lighting.Part2

while true do

    wait(1)

    Part1:Clone().Parent = workspace
    Part2:Clone().Parent = workspace

    wait(3)

    workspace.Part1:Destroy()
    workspace.Part2:Destroy()

end

Yes there is already 2 parts named Part1 , Part2 . then i try to delete it but it doesn’t work.|
image

Move the parts to Lighting and use the script I posted

Check the workspace, also here’s a script that i tried to make for you: (yes I’m putting the parts in ReplicatedStorage.)
local Part = game:GetService(“ReplicatedStorage”).Part

local Part2 = game:GetService("ReplicatedStorage").Part2

while true do

game.Workspace.Part:Destroy()

game.Workspace.Part2:Destroy()

print("Removed.")

wait(1)

Part:clone().Parent = game.Workspace

Part2:clone().Parent = game.Workspace

print("Cloned.")

wait(3)

game.Workspace.Part:Destroy()

game.Workspace.Part2:Destroy()

print("Removed.")

wait(1)

Part:clone().Parent = game.Workspace

Part2:clone().Parent = game.Workspace

wait(3)

end
1 Like

Thanks i will try this ! if it works then i will mark it as the solution .

Also i noticed that you don’t clone the parts again.

1 Like