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

How would I assign an individual number to each player that joins the game?

Hello, my game has a max of 8 players. I need to have a script that assigns a number value to each player. I know how to put a value into a player and know when they disconnect and join, but I just dont know how to give each other them their own number.

for example, player 1 = number 1, player 2 = number 2 and on and on

Thank you

3 comments

2

that already exists, player.UserId

0

good answer, also guywithapoo script requests are not allowed

1

well you see, I wouldnt want to use UserId because what im trying to do is give every player a number for the order they joined in, like the 27th person to join would get number 27. Its all for a script that puts players 1 and 2 into a box using the corresponding numbers for each player. I am having a difficult time explaining this, sorry. Also I do not want a full script, maybe just some ideas.

1 answer

✓ Accepted answer

You could simply use GetPlayers() to do this.

game.Players:GetPlayers()[3] --> this will fetch player 3's player object, if there are that many players.

Here's the rest of the script.

function tpAllPlayers()
	for i,v in pairs(game.Players:GetPlayers()) do
		if workspace[game.Players:GetPlayers()[i].Name] then
			workspace[game.Players:GetPlayers()[i].Name].HumanoidRootPart.CFrame = workspace:FindFirstChild("Spawn" .. i).CFrame
		end
	end
end

Now player 2 will be teleported to an object named "Spawn2" in this case.

1 comment

1

Thank you!

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