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?
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.
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!