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

Is this the correct way to clone and destroy an object? [SOLVED]

DISCLAIMER: I have a made a post like this about 2 months ago. When I tested it in Roblox Studio, nothing got cloned, and nothing got destroyed. Please help if you can.

Hello Fellow Scripters! So this is what I am trying to make: First, you wait 3 seconds then a part will be cloned at this position; (60, 34, 59), and a message will be printed into the output. After that you will wait 5 seconds and the cloned part will be destroyed. Then, some text will be printed again 4 seconds the part was destroyed. Please correct me if I am incorrect! Thanks!

My Code:

wait(3)

local myClone = game.Workspace.Part:Clone()
myClone.Position = (60, 34, 59)

print(The Part has been cloned.)

wait(5)

myClone:Destroy()

wait(4)

print(HAHA That part has been deleted!)
--This should work right?
--Answer if you the answer to this question.

Question(s): On line 3 when we used a variable to define the cloned part, on line number 10 do we still have to call the part "myClone"???

Please do not forget to answer both questions above.

3 answers

✓ Accepted answer

That would have worked but you forgot to give the part a parent, which would be workspace.

So if you do the following everything should be fine.

local MyPart = game.Workspace:FindFirstChild("MyPart")

wait(3)

local CloningPart = MyPart:Clone()

CloningPart.Parent = game.Workspace
CloningPart.Position = Vector3.new(60, 34, 59)

print("The part has been cloned")

wait(5)

CloningPart:Destroy()

wait(4)

print("Part has been destroyed")

also, the way you printed would cause an error since you forgot to add them in quotation marks ("Text") because it's printing out a string

1 comment

0

Okay, thank you for telling me the error and the part I messed up on, your answer has been accepted.

You forgot to set the parent of the clone. Currently the part doesn't exist anywhere. Use this code to set the parent:

mClone.Parent = workspace

Hope this helped!

1 comment

0

Ohhhhh, am I supposed to put that at the beginning of the script? Also, it's "myClone" you have a typo :) Thanks.

You forgot to add Vector.new() and yes, you do need to call the part "myClone" to destroy the part

(myClone needs to be cloned in workspace too)

wait(3)

local myClone = game.Workspace.Part:Clone() --clone it
myClone.Parent = game.Workspace
myClone.Position = Vector3.new(60, 34, 59) --Vector.new

print("The Part has been cloned.")

wait(5)

myClone:Destroy() --destroy the "myClone"

wait(4)

print("HAHA That part has been deleted!")

1 comment

0

Ah yes, when i was in the studio, the vector3.new was there, however, it wasn't functioning...

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