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

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

Asked by
Scythax 35
9 years ago

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

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

#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";
)
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. Scythax 35 — 9y
1
Oh, okay, I'll edit the answer BlueTaslem 18071 — 9y
0
Thanks man, I'm thinking of making a fun game, if you'd like to help just message my user scythax. Scythax 35 — 9y
Ad

Answer this question