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

[SOLVED] How can I use :Clone() on GetChildren?

THIS QUESTION HAS BEEN SOLVED

INFORMATION:

  • I am trying to clone coins in ReplicatedStorage.Coins
  • I am using a server script in ServerScriptService
  • There are multiple coins in ReplicatedStorage.Coins with the same name, "Coin"
  • I am getting no errors in Output
  • I want the parent of the cloned coins to be Workspace
  • ReplicatedStorage.Coins is a Folder

SCRIPT:

for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren(coins)) do
    if coin then
            local cl = coin:Clone(game.Workspace)
    else
        print("No coins found")
    end
end

3 answers

✓ Accepted answer

If you want to clone each object in the coins folder, all you'd have to do is:

for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren()) do
	local clone = coin:Clone()
	clone.Parent = game.Workspace
end

BrainDead's answer is just completely wrong...

3 comments

0

Thank you so much!

0

np

0

np

The parameter in clone is the parent, so if I wanted to clone a Part from Replicated Storage to Workspace, I'd do

game.ReplicatedStorage.Part:Clone(game.Workspace)

For GetChildren, the parameter is a table name, so if you do this code

game.ReplicatedStorage.Coins:GetChildren(coins)

I'd have a table called "coins" with all the children of ReplicatedStorage.Coins inside. Hope this helped!

1 comment

0

I edited the script to what you said and it did not work. I did not get any errors in the output either.

for i,coin in pairs(game.ReplicatedStorage.Coins:GetChildren(coins)) do
	if coin then
        	local cl = coin:Clone(game.Workspace)
	else
		print("No coins found")
	end
end

8 comments

0

Explain the code for him people. If he wants an answer, explain to him why this works instead of what he was doing or how your solution was more effective.

0

I used a in pairs loop. It then goes and checks if there is a coin inside of replicatedStorage.Coins. If so, it sets a variable named cl to the clone of coin. The reason the variable works is because, how he has it. coin:Clone() would be nil, but when you assign it to a variable, for some reason, it works. It also is nice to have it as a var so you can refer to it later.

0

Line 1: W001: Unknown global 'coins'

0

someone downvote this answer...

0

sorry, I realize my error. nvm

0

sorry, I realize my error. nvm

0

sorry, I realize my error. nvm

0

sorry, I realize my error. nvm

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