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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

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...

0
Thank you so much! Dave_Robertson 42 — 4y
0
np zadobyte 692 — 4y
0
np zadobyte 692 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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!

0
I edited the script to what you said and it did not work. I did not get any errors in the output either. Dave_Robertson 42 — 4y
Log in to vote
-1
Answered by 4 years ago
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
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. Nckripted 580 — 4y
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. BrainDead_Dev 135 — 4y
0
Line 1: W001: Unknown global 'coins' Dave_Robertson 42 — 4y
0
someone downvote this answer... zadobyte 692 — 4y
View all comments (4 more)
0
sorry, I realize my error. nvm BrainDead_Dev 135 — 4y
0
sorry, I realize my error. nvm BrainDead_Dev 135 — 4y
0
sorry, I realize my error. nvm BrainDead_Dev 135 — 4y
0
sorry, I realize my error. nvm BrainDead_Dev 135 — 4y

Answer this question