How to player:LoadCharacter() all players?

I’m trying to use Player:LoadCharacter() in a script. However, it only Reloads one random character.

Script:

Players.PlayerAdded:Connect(function(player, teamColor) -- Checking when a new player joins.
	print(player.Name .. " joined the game!")
	player.TeamColor = BrickColor.new("Mid gray")
	local players = game:GetService("Players"):GetPlayers()
	if #players >= 2 then
		print("Enough players.")
		RemoveNEP:FireAllClients() -- Removing NEP GUI
		timeVal.Value = "Intermission..."
		task.wait(15)
		timeVal.Value = "Loading..."
		SpinGame:Clone().Parent = workspace
		wait(SpinGame)
		for i, v in pairs(Players:GetChildren()) do
			if v:IsA("Player") then
				v.Team = game.Teams:WaitForChild("Playing")
			end
		end
		player:LoadCharacter()
	else
		print("Not enough players.")
		ShowNEP:FireAllClients() -- Showing NEP GUI
		timeVal.Value = ""
	end
end)

This is not the entire script but this is the part that I’m reloading the character.
All help is appreciated! :slight_smile:

local Players = game:GetService("Players"):GetPlayers()

for i = 1, #Players do
    local CurrentPlayer = Players[i]

    CurrentPlayer:LoadCharacter()
    task.wait()
end

That should do it! :slightly_smiling_face:

2 Likes

Why not use a pairs loop?

local Players = game:GetService("Players")

for _, player in pairs(Players:GetPlayers()) do 
	player:LoadCharacter()
end
3 Likes

Preference, however, you could do that as well! :smiley:

1 Like

This part of the script only loads the player who joined last:

for i, v in pairs(Players:GetChildren()) do
	if v:IsA("Player") then
		v.Team = game.Teams:WaitForChild("Playing")
	end
end
player:LoadCharacter() 

Instead use :LoadCharacter() on v which is the player of the current iteration:

for i, v in pairs(Players:GetPlayers()) do
	--the if statement isn't needed, because we use :GetPlayers()
	v.Team = game.Teams:WaitForChild("Playing")
	v:LoadCharacter() 
end