I've been wondering how to make #Players or NumPlayers Print as text on a GUI. How would I do this?
#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 and
s, or
s, 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"; )