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

Am I using the Clone() function correctly?

Asked by 4 years ago

So here is my code;

local clonePart = script.Parent

while true do
    newPart = clonePart:Clone()
    newPart.Parent = workspace
    wait(5)
end

Why is it not creating a new part every 5 seconds?

thanks in advance, guys.

0
Is the part script.Parent? iRunzs 20 — 4y
0
The part I wish to clone is script.Parent, yes XxMishMashxX 19 — 4y
0
Can you give me the Script type and location? Ziffixture 6913 — 4y
0
clonePart is in game.Workspace, and the script (which is a normal script - not local) is in game.Workspace.clonePart XxMishMashxX 19 — 4y

2 answers

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

I think it's because lua reads code from top to bottom (line by line) so put wait (5) on line 2 And there's no need to clone a part when you can just instance a part. Keep in mind that cloning is essential if you want to instance the exact model while instance is useful if you just want to instance a part without changing its property try the below code.


while true do -- while loop wait (1) -- waits a second local part = Instance.new( "Part",game.Workspace) -- It instances a part and the put the part in the workspace end

If my answer helped make sure to accept it

Ad
Log in to vote
0
Answered by 4 years ago
local clonePart = script.Parent

while true do
    local position = newPart.Position
    newPart = clonePart:Clone()
    newPart.Parent = workspace
    newPart.Position   = position * Vector3.new(0, 1, 0)
    wait(5)
end

I'm pretty sure this is working but the position is in the same spot so you can't tell

Answer this question