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

local Clone1 = game.ServerStorage.Clone1:Clone()
While true do
part = Instance.new("Part", workspace.Blocks)
part.Anchored = true
part.Size = Vector3.new(3, 3, 3)
part.Position = Vector3.new(0, 1.5, 0)
Clone1.Parent = part
wait(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:

local ServerStorage = game:GetService("ServerStorage")

while true do

    local clone1 = ServerStorage:WaitForChild("Clone1"):Clone()

    local part = Instance.new("Part", game.Workspace.Blocks)
    part.Anchored = true
    part.Size = Vector3.new(3, 3, 3)
    part.Position = Vector3.new(0, 1.5, 0)
    clone1.Parent = part

    wait(1)
end

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.

local Clone1 = game.ServerStorage.Clone1:Clone()
While true do
part = Instance.new("Part", workspace.Blocks)
part.Anchored = true
part.Size = Vector3.new(3, 3, 3)
part.Position = Vector3.new(0, 1.5, 0)
Clone1.Parent = part
wait(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