Assign a variable to players

hey so i have a game where 4 people will be in a lobby, and i basically need to number what player is who / assign a variable to each player

this is what i did:

local Localplayer = game.Players.PlayerAdded:Wait()

local getPlayers = game.Players:GetPlayers()

local players = {

	player1 = getPlayers[1],
	player2 = getPlayers[2],
	player3 = getPlayers[3],
	player4 = getPlayers[4]
}

i swear this used to work, but when i test it in studio with 2 players, player 2 just comes out as nil

i also just tried printing every player and they all come out as nil expect player1

its because you are waiting for playeradded, which only waits for 1 player, then before the other players have loaded it will print out the 1 player that has loaded

that makes a lot of sense thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.