i want make a time counting but only when the server have enough player, plz help!
✓ ANSWER ACCEPTED
Run a script when server have enough people?
1 answer
✓ Accepted answer
You can use the following script:
local MINUMIM_PLAYERS = 3 --CHANGE THIS TO BE THE MINIMUM AMOUNT OF PLAYERS YOU NEED TO START GAME
--this function runs whenever a player is added into the game:
game.Players.PlayerAdded:Connect(function()
--gets the current amount of players in game
local numPlayers = #game.Players:GetPlayers()
--if the number of players in game is greater than or equal
-- to the minimum number of players needed,
-- then run the code that you wanted to
if numPlayers >= MINUMIM_PLAYERS then
--We have enough players, do stuff:
print("we have enough players in game")
end
end)
Something that might be handy for testing - studio has a feature where you can create a test server where you can load multiple players into your game. That way you don't need 3 actual people to test your code, you can emulate those three people playing your game in studio. here's how you'd do that
This discussion is preserved as it was. New answers, comments, and votes are closed.
