Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GetChildren() and Clone() help?

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

✓ Accepted answer

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

2 comments

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?

0

Well, I could try Parenting the objects by themselves, so thanks for the suggestion!

This discussion is preserved as it was. New answers, comments, and votes are closed.