Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this cloning script doing this?

Asked by 9 years ago

I have a script that clones a model. Here's the script:

local clone1 = game.Workspace.glassPanes:Clone()
local clone2 = game.Workspace.glass1:Clone()
local clone3 = game.Workspace.glass2:Clone()

clone1.Parent = workspace
clone2.Parent = workspace
clone3.Parent = workspace

The script works fine on the first try, but when it fires twice, it breaks and the output says:

The Parent property of glassPanes is locked, current parent: NULL, new parent workspace

Why is it breaking, and can anyone help me?

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

It's breaking because when you clone the item, it is stored in some location I would assume to be nil. When you take that clone and drag it into workspace, then it gets moved. Once that clone is gone, it is gone for good. You can make a clone of a clone though, and it should not break.

local clone1 = game.Workspace.glassPanes:Clone()
local clone2 = game.Workspace.glass1:Clone()
local clone3 = game.Workspace.glass2:Clone()

--So you can keep replaying this portion of the script and it should work.
local cloneuno = clone1:Clone()
local clonedos = clone2:Clone()
local clonetres = clone3:Clone()
cloneuno.Parent = workspace
clonedos.Parent = workspace
clonetres.Parent = workspace

Alright, I will make a example. If you were to make a regen button for say, a building set. Then you would start off with clone = script.Parent.Model:Clone(), then later when you have the touched event, you would have clone.Parent = workspace. Well you have basically used up your clone, and you can't hit the button again.

Try this scenario now, you start the script with clone = script.Parent.Model:Clone(). This means you have a clone saved in the script or a unknown location. Later when you touch the brick, then you should have newclone = clone:Clone() newclone.Parent = workspace. This way, you still have that first clone in that unknown location, and you're just making a copy of it to place into workspace. This code you can use over and over again.

0
Check out line 8. Redbullusa 1580 — 9y
0
There is nothing moving the clone, although in another script it gets deleted soon after. This doesn't explain why it would be stored in a location that is nil the second time whyOmustOitObeOme 7 — 9y
Ad
Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

What you are doing here is not cloning an object and putting the clones in different places, but you are cloning an object and trying to put that clone in multiple places, which can't be done. Here's what you should do instead:

game.Workspace.glassPanes:Clone().Parent = game.Workspace
game.Workspace.glass1:Clone().Parent = game.Workspace
game.Workspace.glass2:Clone().Parent = game.Workspace

What my code does is clone an object, and place that specific clone in the Workspace. It can work multiple times since it re-clones the object. Your code set a certain clone as a variable, such as clone1 or clone2, and tried to put it in different spots. It's kind of hard to understand, but trust me.

Please accept my answer and upvote if it helps you!

Answer this question