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

Is this the correct way to find the current amount of players in the game?

Asked by
Jxemes 75
7 years ago

I have a part of my script which needs to find out how many people are in the game. If there is less than 4 people, then it will turn into a longer intermission until one more person joins. If there is 4 or more people, then the script will find how many players are in the game, and copy the value to an IntValue. This IntValue will track the people leaving so the script can decide if it will be an elimination round, or a non-elimination round.

If there is a more efficent script than this, then I might as well keep my project on hold and do something easier to learn more about LUA.

for i, v in pairs(game.Players:GetChildren()) do
    if v.Value <= 4 then
        replicatedstorage.gameStatus.Value = ("Intermission1")
    end
    if v.Value >= 4 then
        replicatedstorage.gameStatus.Value = ("NewGame")
        replicatedstorage.peopleInRace.Value = v.Value

Note: I have ends in the script, but I didn't copy it into here. I haven't tested it yet because I'm still scripting it. So I just need some information if I am doing this right.

gameStatus is a StringValue, it will tell the PlayerGui's Status bar of what it is on (Intermission, In race, etc.) peopleInRace is an IntValue, that mentioned earlier, will track how many people will be in the race.

If you need more information of the script, just reply back. Just need to know if this would work, and if there is another way that is more efficent than this.

1 answer

Log in to vote
1
Answered by 7 years ago

A better way to do this is

#game.Players:GetPlayers()

The # returns the length of the array that is returned by GetPlayers()

0
Thanks, I'll just off that project for a few weeks. Jxemes 75 — 7y
Ad

Answer this question