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

how do I check how many players there are in game? using scripts

Title

Nothing much to describe

Answers/Comments are appreciated

1 answer

✓ Accepted answer

This is pretty easy, you get the children of players and then get the table size by putting a '#' for it

function GetPlayers()
	return #game.Players:GetPlayers()
end

while wait(1) do
	local Players = GetPlayers()
end

If you have questions or I made a typo, just ask

(You can also count them, but this way is easier, if you want for example to only count players with a value inside them named 'InGame' you can do things like this)

function GetPlayers()
	local Players = {}
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild('InGame') and v:FindFirstChild('InGame').Value then
			table.insert(Players, v)
		end
	end
	return #Players
end

while wait(1) do
	local Players = GetPlayers()
end

4 comments

0

So if I add a table ( tab = {} ) should i add tab = {GetPlayers()}?

0

Wdym, don't understand what you're trying to say?

0

Nevermind but thanks

0

np

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