|
| 16 Aug 2017 04:08 AM |
repeat wait() until game.Players
if game.Players.NumPlayers > 0 then print(game.Players.NumPlayers .. " player online") elseif game.Players.NumPlayers == 0 then print("0 players online") end
print("print()") |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 16 Aug 2017 04:12 AM |
local Players = game.Players:GetPlayers() print(#Players:GetPlayers() > 0 and #Players:GetPlayers().." player(s) online" or "0 players online") |
|
|
| Report Abuse |
|
|
Mitko0o1
|
  |
| Joined: 30 Nov 2010 |
| Total Posts: 5725 |
|
|
| 16 Aug 2017 04:13 AM |
if game.Players.NumPlayers > 0 then print(game.Players.NumPlayers .. " player online") else print("0 players online") end
|
|
|
| Report Abuse |
|
|
Ajastra
|
  |
| Joined: 01 Aug 2017 |
| Total Posts: 1461 |
|
|
| 16 Aug 2017 04:13 AM |
Hi yhat. You don't need to wait for game.Players, and if you did, that code would error.
You could also shorten the elseif into a simple else with no condition, as there can't be a negative number of players in the game.
If you want to shorten it even more, we can use the "and" and "or" operators:
print(game.Players.NumPlayers > 0 and game.Players.NumPlayers .." players are online" or "There are no players online.")
The "and" operator returns its first operand if it is falsey, otherwise it returns its second. The "or" operator returns its first operand if it is truthy, otherwise it returns its second. The "and" operator has higher operator precedence than "or".
|
|
|
| Report Abuse |
|
|
|
| 16 Aug 2017 04:15 AM |
nah it doesnt error, it makes it so you can wait for the player to load in, without it, it's just printed when the server starts
print("print()") |
|
|
| Report Abuse |
|
|
Ajastra
|
  |
| Joined: 01 Aug 2017 |
| Total Posts: 1461 |
|
|
| 16 Aug 2017 04:17 AM |
If it did not exist, you would get a not valid member of DataModel error, you don't need it lol.
|
|
|
| Report Abuse |
|
|
|
| 16 Aug 2017 04:19 AM |
im testing it right now :/
print("print()") |
|
|
| Report Abuse |
|
|
Ajastra
|
  |
| Joined: 01 Aug 2017 |
| Total Posts: 1461 |
|
|
| 16 Aug 2017 04:22 AM |
If you don't believe me, try this:
repeat wait() until game.ThingDoesntExist
You can just call wait() by itself, or use the game.Players.PlayerAdded event. :)
|
|
|
| Report Abuse |
|
|
Sprudge
|
  |
| Joined: 06 Oct 2012 |
| Total Posts: 145 |
|
|
| 16 Aug 2017 04:30 AM |
| Ajastra he's right you're wrong it doesn't cast errors. Just because you're OBC doesn't mean you are a know it all. You joined in 2017. |
|
|
| Report Abuse |
|
|
Ajastra
|
  |
| Joined: 01 Aug 2017 |
| Total Posts: 1461 |
|
|
| 16 Aug 2017 04:35 AM |
I thought that being a member of the Outrageous Builders Club would instantly get me into the "Master Scripter" group, but I suppose I was wrong.
Perhaps my phrasing was poor.
"if you did, that code would error."
I meant that if you DID need to wait for it, it would error because it would not exist at one point. It won't error because you don't - which is why it's pointless.
print(game.ThingThatDoesntExist)
If you execute that code, you'll see that it will give you an error. This is what I meant. I wasn't wrong.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 16 Aug 2017 04:46 AM |
| unfortunately, it takes skill rather than a big wallet :/ |
|
|
| Report Abuse |
|
|
kevini44
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 129 |
|
|
| 16 Aug 2017 05:17 AM |
If #game.Players:getChildren()> 0 then --someone ia there Else
--noone... End |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2017 05:23 AM |
| Ajastra is right. You don't need to wait for game.Players, and your code would error if it didn't exist |
|
|
| Report Abuse |
|
|
drysty
|
  |
| Joined: 07 Dec 2013 |
| Total Posts: 1913 |
|
|
| 16 Aug 2017 05:29 AM |
if true do
I.dont.script I'll.just.go.now bye = something |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 16 Aug 2017 05:32 AM |
| print(game.Players.NumPlayers..' player(s) online') |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 16 Aug 2017 12:55 PM |
| NumPlayers is deprecated btw |
|
|
| Report Abuse |
|
|
Ajastra
|
  |
| Joined: 01 Aug 2017 |
| Total Posts: 1461 |
|
|
| 16 Aug 2017 12:59 PM |
I wasn't aware of this, it must've happen recently. Thank you for pointing this out, LaeMVP.
Consider my other posts in this thread void, opt for #game.Players:GetPlayers().
|
|
|
| Report Abuse |
|
|
|
| 16 Aug 2017 02:39 PM |
@lae oh seriously? thanks for letting me know ;)
print("print()") |
|
|
| Report Abuse |
|
|