Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Run a script when server have enough people?

Asked by 4 years ago

i want make a time counting but only when the server have enough player, plz help!

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

Ad

Answer this question