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

How to make infinite clones? [closed]

Asked by 9 years ago

Okay so I have a part that drops clones of a part that does damage. But I need an infinite amount of clones, because I need to copy and paste this block over a few times

But what my script does is drop a part, then pick it back up and drop it again, but this doesn't work with many parts

Here's the script:

rock = workspace.Fallen:Clone()
pos = script.Parent

while true do
    wait(math.random(2,4))
    rock.Parent = workspace
    rock.Position = pos.Position 

end

Locked by TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Since 'rock' is assigned to workspace.Fallen:Clone() only, it would make sense that the part is re-positioned to the position of 'pos'.

'rock' is only referring to the cloned version of workspace.Fallen and nothing else. The 'while' loop doesn't create more, it is only using the same old 'rock', not making new clones.

Just reposition your 'rock' variable after the wait(math.random(2,4)) method:

pos = script.Parent

while true do
    wait(math.random(2,4))
    rock = workspace.Fallen:Clone() -- This will clone and re-position that clone every 2-4 seconds(with a new clone, of course)
    rock.Parent = workspace
    rock.Position = pos.Position 
end

Compare the aforementioned code from this:

rock = workspace.Fallen:Clone() -- This is cloning 'workspace.Fallen'.
pos = script.Parent

while true do
    wait(math.random(2,4))
    rock.Parent = workspace     -- This will set the parent of 'workspace.Fallen's' same old clone
    rock.Position = pos.Position    -- This will re-position the same old clone of 'rock'
end
Ad
Log in to vote
1
Answered by
Bman8765 270 Moderation Voter
9 years ago

You need to create a local clone each time it does this. Before the script was using the same clone just positioning it over and over again. Here is an example:

pos = script.Parent

while true do
    wait(math.random(2,4))
    local rock = workspace.Fallen:Clone()
    rock.Parent = workspace
    rock.Position = pos.Position 

end

Now it should create a new clone stored in a variable then you can do whatever you want to this variable and because it is local it will create a new one every time you loop!