Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

2
that already exists, player.UserId theking48989987 2147 — 4y
0
good answer, also guywithapoo script requests are not allowed Gameplayer365247v2 1055 — 4y
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. guywithapoo 81 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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
Thank you! guywithapoo 81 — 4y
Ad

Answer this question