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

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

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

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)

2 comments

0

The contents of the folder are moved somewhere, but not to the player. In fact, I can't find them anywhere

0

Are you sure? Any errors in the output? The script seems perfectly fine for me. @Daanni

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