A bad scripting practice I've encountered on the Roblox Education Site

Hello, I’ve been running around through the education site when I found this script shown on there that was made in a tutorial for making a Battle Royale Game. Im not sure where to post this so Im just going to post it here in hoping that a moderator on the forum or someone who has access to the education hub can fix this error.

while true do
   repeat
      print("Starting intermission")
      wait(gameSettings.intermissionDuration)
   until Players.NumPlayers >= gameSettings.minimumPlayers
   print("Intermission over")
   wait(gameSettings.transitionTime )
end

If you don’t understand the issue here, Roblox are telling players to use a property that has been Deprecated, as stated on the Roblox API.

It even says on the api that NumPlayers and numPlayers is deprecated and will error on use.

You should Instead use game.Players:GetPlayers() to find the integer of players and set a variable value to the value of it, it should return an int value when printed out.

local playerVar = #game.Players:GetPlayers() print(playerVar)

Just something I wanted to share, unless im wrong, please tell me.

2 Likes

I’ve also noticed that NumPlayers is even on the new api site, even it says that its deprecated.

numPlayers is also deprecated as stated in the old Roblox API Reference manual, but its not shown on the new api site.

I mean sure Players.NumPlayers is depecrated but it doesnt mean that roblox will fully remove it someday, plus it works the same as #game.Players:GetPlayers()

Also that returns a table of player instances that are in the server, use print(#playerVar) or print(table.getn(playerVar)) to get the int value.

1 Like

Roblox said themselves that it is read only, and will error when used.

Roblox meant that it will error when you try to change the value, not reading the value as seen here:

1 Like

Oh, well thanks for telling me. But then what’s the point in Roblox marketing this as deprecated?

Because its no longer efficient to use, like honestly why have a whole property just to check the amount of players that are in the server when you could just use #game.Players:GetPlayers()? Seems dumb to me

1 Like

As in its been surpassed by another?

And if it isn’t, why still use it over a updated and more efficient version?

Well if you couldn’t tell the documentation was made like ~4 years ago (as seen in the image’s topbar & the usage of rthro), so there would be some parts of their code where it would be outdated.

image

1 Like

You’re misunderstanding what deprecation means. It is basically like saying its no longer supported. This means that were this property to break in the future with an update it won’t be fixed.
The reason they are kept and referenced, and not immediately deleted is because it would break all older scripts and games that utilize it.

Its not a “You can’t and shouldn’t use it” but rather a “Its not recommended to use it”

On that note, you could say every single script that utilizes wait() is a “bad scripting practice” since its been deprecated for task.wait()

2 Likes

Seems a bit lazy on there part if it was, they could have made an updated version of the tutorial due to the fact that the API gets changed every now and then.

Thanks for the information :+1:

wrong person

1 Like