Is this an efficient way to get the number of players in a game?
Asked by
5 years ago Edited 5 years ago
Hello, I have created a script that has a NumberValue in a Folder inside of Workspace. Whenever somebody joins, it adds + 1 to the NumberValue. Whenever someone leaves, it does - 1. I am just curious to know if the way I am doing this is efficient because I know there is other ways of doing this. I also forgot to mention that whenever someone joins it just prints out 0 for some reason. Thanks!
Code:
01 | numbers = game.Workspace.Numbers |
02 | value = numbers.PlayerCount.Value |
04 | game:GetService( "Players" ).PlayerAdded:Connect( function () |
05 | numbers.PlayerCount.Value = numbers.PlayerCount.Value + 1 |
10 | game:GetService( "Players" ).PlayerRemoving:Connect( function () |
11 | numbers.PlayerCount.Value = numbers.PlayerCount.Value - 1 |
Thank You!