LoadCharacter only loads One Character

I am making a round system where, after a round ends, each character is loaded onto a new team and teleported to the lobby. But, only one player has their character loaded successfully, and nothing happens to the other players.

code:

	for i, plr in pairs(game.Players:GetChildren()) do
			local char = plr.Character
			if plr.TeamColor ~= BrickColor.new("Dark stone grey") then
			plr.TeamColor = BrickColor.new("Dark stone grey")
			plr.leaderstats.K.Value = 0
			plr.leaderstats.D.Value = 0
			wait(0.05)
				plr:LoadCharacter()
				char.PrimaryPart.Position = Vector3.new(game.Workspace.Lobby.lobbyspawn.Position + Vector3.new(0,4,0))
				
			end
		end
2 Likes

What happens if you use game.Players:GetPlayers() instead?

You’re doing the local char BEFORE the loadcharacter, and then try to move the char after that… which won’t work, since it saves the PREVIOUS character, BEFORE the loadcharacter, so after the loadcharacter is executed, the previous character obviously gets deleted and so becomes nil… also use task.wait() instead of wait() and wait until the character fully loads using “repeat task.wait(.1) until plr.Character” or else it won’t work as good

for i, plr in pairs(game.Players:GetChildren()) do
			if plr.TeamColor ~= BrickColor.new("Dark stone grey") then
			plr.TeamColor = BrickColor.new("Dark stone grey")
			plr.leaderstats.K.Value = 0
			plr.leaderstats.D.Value = 0
			    plr:LoadCharacter()
			    repeat task.wait(.1) until plr.Character and plr.Character:FindFirstChild("HumanoidRootPart")
			    local char = plr.Character
			    char.PrimaryPart.Position = Vector3.new(game.Workspace.Lobby.lobbyspawn.Position + Vector3.new(0,4,0))
				
			end
		end
1 Like

I personally think its

Have you tried removing that?

1 Like

It’s also worth noting that doing this

could be done better. There’s the Player.Team property that would be more readable and make sure that they’re on the correct team.

Player #Team | Documentation - Roblox Creator Hub