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

GetChildren() and Clone() help?

Asked by 9 years ago

I made a script to make a backup of every model inside a group, and then clone them in ReplicatedStorage, but it doesn't seem to work. Can someone help me with this?

Script

Upgrades = script.Parent:GetChildren()

for i = 1, #Upgrades do
    Upgrades[i]:Clone()
    Upgrades[i].Parent = game.ReplicatedStorage.Upgrades
    Upgrades[i]:Destroy()
    wait()
end

The script's inside a model, sharing space with some other models.

1 answer

Log in to vote
4
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

You're trying to set the Parents of the Object itself, not the clone of it. The Clone is never touched at all, actually. Here's a fix:

Upgrades = script.Parent:GetChildren()

for i = 1, #Upgrades do
    Upgrades[i]:Clone().Parent = game.ReplicatedStorage.Upgrades --Yes, you can do this.
    Upgrades[i]:Destroy()
    wait()
end
0
Isn't it redundant to clone and then delete the original? Wouldn't it be better to outright set the .Parent of `Upgrades[i]` to the model in ReplicatedStorage? BlueTaslem 18071 — 9y
0
Well, I could try Parenting the objects by themselves, so thanks for the suggestion! TheArmoredReaper 173 — 9y
Ad

Answer this question