Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make an error announcement if there is not enough players for a repeat?

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

1 answer

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 =) ) )

2 comments

0

I already have something similar to that in another script. But I need it to check just in case otherwise it would just keep checking for 2 diff teams and not work.

0

You can do a lobby script, when there are enough player to start the game then the game will select randomly a player and put it into the King Team =)

This discussion is preserved as it was. New answers, comments, and votes are closed.