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

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

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

✓ Accepted answer

A better way to do this is

#game.Players:GetPlayers()

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

1 comment

0

Thanks, I'll just off that project for a few weeks.

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