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

How can you print the number of players, and have it on a GUI text?

I've been wondering how to make #Players or NumPlayers Print as text on a GUI. How would I do this?

1 answer

✓ Accepted answer

#game.Players:GetPlayers() or game.Players.NumPlayers are both numbers. You should be able to just set a gui object's Text property to them, e.g.:

someLabel.Text = game.Players.NumPlayers;

Or, you can add some label to it, which will also explicitly cast it to a string:

local num = game.Players.NumPlayers;
someLabel.Text = "There "
	.. (num == 1 and "is" or "are") .. " " .. num
	.. " player" .. (num == 1 and "" or "s") .. " playing";

Note that the ands, ors, and == just form a fancy way to make the plurals right :) Without it, more simply:

someLabel.Text = "There are " .. num .. " players playing"

Alternatively, we can just print the same things:

print( game.Players.NumPlayers );

local num = game.Players.NumPlayers;
print(
	"There "
	.. (num == 1 and "is" or "are") .. " " .. num
	.. " player" .. (num == 1 and "" or "s") .. " playing";
)

3 comments

0

Thanks for the answer, I like it alot but I'd like to as well know how to print the "Number" of players? As in print I mean in the output.

1

Oh, okay, I'll edit the answer

0

Thanks man, I'm thinking of making a fun game, if you'd like to help just message my user scythax.

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