generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: any way to shorten this?

Previous Thread :: Next Thread 
yhatayhatahoohoo is not online. yhatayhatahoohoo
Joined: 19 Jan 2011
Total Posts: 1988
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 is online. 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 is not online. 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 is not online. 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
yhatayhatahoohoo is not online. yhatayhatahoohoo
Joined: 19 Jan 2011
Total Posts: 1988
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 is not online. 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
yhatayhatahoohoo is not online. yhatayhatahoohoo
Joined: 19 Jan 2011
Total Posts: 1988
16 Aug 2017 04:19 AM
im testing it right now :/


print("print()")
Report Abuse
Ajastra is not online. 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 is not online. 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 is not online. 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 is not online. 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 is online. 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
10MilesWide is not online. 10MilesWide
Joined: 06 Aug 2014
Total Posts: 2220
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 is not online. 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 is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
16 Aug 2017 05:32 AM
print(game.Players.NumPlayers..' player(s) online')
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
16 Aug 2017 12:55 PM
NumPlayers is deprecated btw
Report Abuse
Ajastra is not online. 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
yhatayhatahoohoo is not online. yhatayhatahoohoo
Joined: 19 Jan 2011
Total Posts: 1988
16 Aug 2017 02:39 PM
@lae oh seriously? thanks for letting me know ;)


print("print()")
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image