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

How can i use :Clone() on GetChildren?

Asked by 6 years ago

Hello, i am making minigames. I want to make this --> If there is Tools folder in map. The tools will in Player.Backpack i want to this but its not working. Sorry my english and scripting isnt really good.

        if workspace:FindFirstChild(map.Name).Tools then
            local tools = workspace:FindFirstChild(map.Name).Tools:GetChildren()
            tools:Clone().Parent = Player.Starterpack
        else
            print('No gears')
        end

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago

Clone is only a function of instances. GetChildren returns a normal array. You have to loop through the array to actually use the instances.

btw FindFirstChild is for verification (returns either a child or nil), so don't try to immediately use its result. I'll assume map.Name is valid.

if workspace[map.Name]:FindFirstChild("Tools") then
    for _,tool in ipairs(workspace[map.Name].Tools:GetChildren()) do
        tool:Clone().Parent = Player.Starterpack
    end
else
    print('No gears')
end
0
Thanks bro! FrezeTagger 75 — 6y
Ad

Answer this question