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

How would I go about moving all objects from a folder into a player character?

Asked by
Daanni 10
8 years ago

I'm trying to make a script that moves all of the children of the folder

script.Character

into

newPlayer.Character

(which is the player character). The code I have right now does not do anything. How would I move all children on my folder into the character?

game.Players.PlayerAdded:connect(
function(newPlayer)
newPlayer:WaitForChild("PlayerGui")
local PlayerGuiFolder = script.Player.PlayerGui:clone()
PlayerGuiFolder.Parent = newPlayer.PlayerGui
local character = script.Character:GetChildren()
character.Parent = newPlayer.Character
end

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Well, you have the right idea, just using the wrong function. There are a few ways to achieve your goal, but I prefer to use a generic loop, which is commonly known as the for loop that includes pairs. Script:

game.Players.PlayerAdded:connect(function(newPlayer)
    newPlayer:WaitForChild("PlayerGui")
    local PlayerGuiFolder = script.Player.PlayerGui:clone()
    PlayerGuiFolder.Parent = newPlayer.PlayerGui
    for i,v in pairs(script.Character:GetChildren()) do
        v.Parent = newPlayer.Character
    end
end)
0
The contents of the folder are moved somewhere, but not to the player. In fact, I can't find them anywhere Daanni 10 — 8y
0
Are you sure? Any errors in the output? The script seems perfectly fine for me. @Daanni Shawnyg 4330 — 8y
Ad

Answer this question