How can I fix this script to work so that say it waits 10 seconds and there is only 1 player in the server and it couldn't find another person to be a king. How can I make it insert a message and announce "Error: Not enough players. Restarting..."?
local list = game.Players:GetChildren() f = list[math.random(1, #list)] repeat wait(0.5) b = list[math.random(1, #list)] print(b.Name .. ", " .. f.Name) until f.TeamColor ~= b.TeamColor
The script you posted doesn't mean nothing.
What you need to do is to check how many players there are in the server by using the game.Players.NumPlayers
field.
Do something like this:
function onUpdate() if game.Players.NumPlayers <= 0 then print("Not enough players to start the game!") wait(2) onUpdate() -- Every 2 seconds the function will be recalled. else print("Selecting the king!") -- Your custom king select code end end -- Calling for the first time the function onUpdate()
That simply call for the first time the "onUpdate" function which says:
Are there enough player to start the game? YES: Start the game; NO: Print "Not enough players to start the game!"), wait 2 seconds, recall the same function: ( Are there enough player to start the game? YES: Start the game; NO: ..... recall the same function: ( again and again until there are enough player to start the game =) ) )