Reparenting the characters

I’ve been looking for just a simple answer but I can’t find anything clear. All I’m trying to do is reparent the player’s character model to a folder in the workspace via the server. How would I go about this or am I just blind and didn’t see an article? If so, please link it.

Thanks!

1 Like

what. you just… do a loop for the players and get their characters and put them in a folder?

for i,v in pairs(game.Players:GetChildren()) do
v.Character.Parent = workspace.Folder
end

Apologies for not sending my code.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.Parent = workspace.Interactive
	end)
end)

This doesn’t seem to be working. I’m not an expert with this though, so should I be using a loop intead?

maybe because your character doesn’t spawn in when you do the checks.
so we can do a forever loop that checks if ur character is in workspace and not
in folder, sorry for bad explanation

while wait() do
for i,v in pairs(game.Players:GetChildren()) do
if workspace:FindFirstChild(v.Name) then
v.Character.Parent = workspace.Interactive
end
end
end

This makes it so that everytime it detects a character in the workspace it will automaticly put it in the folder.

edit
I created a folder name "Interactive" and used the script that I've created, and it works!

1 Like

Success! Thank you for the help. Just a question though, why isn’t the character loaded when CharacterAdded is triggered? I get that appearance might not load right away but shouldn’t the model itself where objects can load into be parented?

That doesn’t seem to be working. I’m not an expert with these things though, sorry.
There is also another event feature of player class called
player:CharacterAppearanceLoaded()
that waits for the appearance to load
maybe one day it will help u

1 Like

If there are other things interacting with the script, what might happen in solo testing is that the player gets added before the PlayerAdded event get set up, though that is probably not the issue, what might be the issue is the Character get added too quickly and any changes you make are applied too quickly, so, here are a few fixes, the first one, is to loop through the GetPlayers() method once after setting up PlayerAdded so players already in the game will also have the function ran, and the second fix will be to simply wait 1 second before applying changes, also, check if the character has spawned in already, so it also gets the change

local function onCharacterAdded(char)
	wait(1)
	char.Parent = workspace.Interactive
end)

local function onPlayerAdded(plr)
	plr.CharacterAdded:Connect(onCharacterAdded)
	local char = plr.Character
	if char then
		onCharacterAdded(char)
	end
end)

game.Players.PlayerAdded:Connect(onPlayerAdded)
for i, v in ipairs(game.Players:GetPlayers()) do
	onPlayerAdded(v)
end
2 Likes

in this post, TheGamer has a list that shows the order of how character loading works. keep in mind the proposed “new” loading is not live yet so currently roblox uses the “old” method. you can see that a bit after CharacterAdded is fired, the game will parent the character to the workspace. that means if you try to immediately parent the character after CharacterAdded, the game will just reparent them to the workspace

1 Like

Oh, forgot about this! This works the same as the loop but (I think) takes less processing.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		character.Parent = workspace.Interactive
	end)
end)
1 Like