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

How do I make a script clone stay inside of a new instance?

Asked by 5 years ago

So I have made a script where a part gets created. Clone1 is a script that is stored in serverstorage The issue is that when another part gets created. The Clone1 changes Parent to the new part that gets created. And I want every part that gets created to have this script inside of it. How do I fix this

1local Clone1 = game.ServerStorage.Clone1:Clone()
2While true do
3part = Instance.new("Part", workspace.Blocks)
4part.Anchored = true
5part.Size = Vector3.new(3, 3, 3)
6part.Position = Vector3.new(0, 1.5, 0)
7Clone1.Parent = part
8wait(1)

1 answer

Log in to vote
1
Answered by
Lazarix9 245 Moderation Voter
5 years ago

I wrote a script that would work, here it is:

01local ServerStorage = game:GetService("ServerStorage")
02 
03while true do
04 
05    local clone1 = ServerStorage:WaitForChild("Clone1"):Clone()
06 
07    local part = Instance.new("Part", game.Workspace.Blocks)
08    part.Anchored = true
09    part.Size = Vector3.new(3, 3, 3)
10    part.Position = Vector3.new(0, 1.5, 0)
11    clone1.Parent = part
12 
13    wait(1)
14end

As you can see, the only thing I did was put the clone1 variable inside the while loop and add an end at the end.

I'm gonna try my best to explain why your code didn't work.

1local Clone1 = game.ServerStorage.Clone1:Clone()
2While true do
3part = Instance.new("Part", workspace.Blocks)
4part.Anchored = true
5part.Size = Vector3.new(3, 3, 3)
6part.Position = Vector3.new(0, 1.5, 0)
7Clone1.Parent = part
8wait(1)

First, the Clone1 variable doesn't change, it always returns the same object so when you set the parent to the new part, it just moves it, and doesn't create a new object. We fixed that by moving the variable inside the while loop to clone the script repeatedly which changes the object that it's referencing. Confusing, yes. Sorry, I'm not good at explaining stuff...

Then I don't know if this made any difference but end closing the loop is there because otherwise, it should throw an error that it expects an end at the end of the file. That's all; if you've got any questions you can ask in comments.

Ad

Answer this question