More than 1 player Error

Hello everyone! I am making a game where each round there is a random obby map, and now I am trying to do something more complex in my script. I want to have “tournaments” with many rounds, and I wanted to make the game start when there are 3 players or more. In my game there are 3 teams: Completed Spectators and Contestants.

So I wanted the first round to teleport all the spectators to the map, and then in the next rounds, teleport the players who are alive, that means, the ones that are in Completed team during intermission.

So basically, my script had a while true do loop, where it would make an intermission, teleport players to map, then teleport to lobby and destroy map… Regardless of the player’s team, it was teleporting everyone.

Now i changed the beginning of the loop to start only when there is more than 1 player (line 24)

However, when i joined a server with me and my alt account, the intermission didn’t start, and I saw an error when i pressed F9:

Did I type something wrong in line 24? Or do I have to invert lines 23 and 24? I have no idea why its not working… Or maybe did I reference the number of players in a way that the script didn’t understand?

Please help

Why not test within studio using Multi client simulation? https://developer.roblox.com/en-us/articles/game-testing. Seems pretty inefficient to publish the game, then join the server with an alt account without access to studio.

You can easily click on that error within output and trace back your errors on what caused it at line 24.

Otherwise the error is caused by something inside the while true do loop. I believe a quick fix will be to insert a wait(1) before the if statements because without that then if there is only 1 player the while true do loop will run forever.

like

while true do
wait(1)
if #Players:GetPlayers()>1 then
end
--no yielding if condition is not met therefore while loop will loop way too fast
end

Next time use ``` to format your code so it’s easier for us to see and help, images are the worst.

print("hi")

in your while true do loop
change

while true do

to

while wait() do
1 Like

This usually happens when you don’t add a wait() to while true do loops.

Add this at the end of the while true do:

wait()
1 Like

Your script will timeout if the condition is not met (false or nil).
You’ll need to add a wait() in case that statement is not true (if #Players:GetPlayers()>1).

1 Like

you are always checking that there is more then 1 player, that’s not good.
you can do this, witch checks every frame if there is more then 1 player:

local runService = game:GetService("RunService")
runService.Heartbeat:Connect(function()
	if #Players:GetPlayers() > 1 then
		-- do stuff here
	end
end)

or this, that gives delay of something like 15 miliseconds every check:

while wait() do
	if #Players:GetPlayers() > 1 then
		-- do stuff here
	end
end
1 Like