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:
numbers = game.Workspace.Numbers value = numbers.PlayerCount.Value game:GetService("Players").PlayerAdded:Connect(function() numbers.PlayerCount.Value = numbers.PlayerCount.Value + 1 wait(1) print(value) end) game:GetService("Players").PlayerRemoving:Connect(function() numbers.PlayerCount.Value = numbers.PlayerCount.Value - 1 wait(1) print(value) end)
Thank You!
yes, its ez bro
numbers = game.Workspace.numbers --Value local players = game:GetService("Players") --Get the service local child = players:GetChildren() --Get every player in the list, this returns an array, but can also be used with #, example #child, to get the exact number print(#child)
if this helped then please mark this as the answer