Heya! I’m hoping to create a system that does the following:
Detects the amount of players in a game
For every 5 players in game it’ll +1 number that will display onto a ‘textlabel’ (for example, if 10 players are in game the sign would say “2”, I’m hoping to allow this to update so if 5 people left the game it’d be back to ‘1’ etc…
This system would be used for a theme park game to have a ‘rough estimate’ wait time for a ride depending on the amount of players in-game.
I’m unsure how to go by this and what method is best to achieve what I want.
Thanks!
You can do #game.Players:GetChildren() to get the number of players, and then divide it by 5 and round it to get the count you want. You can use PlayerAdded and PlayerRemoving to update the text.
Assuming the text label is placed in Starter Gui this is how I’d do it:
Place a server script within server script service
Add player added and player removing functions attached to those events
When they fire, check if the number of players via #game.Players:GetPlayers(), and check if the number is below five
If it’s 5, fire a remote event using FireAllClients() within replicated storage with an argument (what you want to show, in this case 1). Do the same with if there were 10 players.
Place a local script within the text label and listen for the event using OnClientEvent. receive the first parameter and set the text label’s text to the number.
If it’s on a surface gui, Don’t use a remote event and just get a path to it. Once you found it, set it’s text to what you want.