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

Help with game.Players.NumPlayers?

The whole code works perfect but I just added in "while game.Players.NumPlayers > 2 do" instead of "while wait() do" and what I want is to make a message with "Message1("Needing 2+ players to start")" if there are less than 2 players in the game.

--I have more code up here but not gonna paste because long code.
while game.Players.NumPlayers > 2 do
	Horn:Play()
	GetIntermission()
	Message1("Setting up game...")
	Horn:Stop()
	Announcment:Play()
	wait(2)
	Message2(" ")
	GetMap()
	wait(1)
	GetPlayers()
	GetGametime()
	Message1("Game ending...")
	wait(2)
	ReturnPlayers()
	RemoveMap()
end

3 answers

You was making it ask if their was more players then 2 online if so then it would return true but you want it to return true if their is less then 2 players online so 1 > 2 = false but 1 < 2 = true
1 < 2 = if 1 is less then 2 other words if 1 is less then 2 then return true if not then false 1 > 2 = if 1 is greater then 2 other words if 1 is higher then 2 then return true if not then false

while game.Players.NumPlayers < 2 do
    Horn:Play()
    GetIntermission()
    Message1("Setting up game...")
    Horn:Stop()
    Announcment:Play()
    wait(2)
    Message2(" ")
    GetMap()
    wait(1)
    GetPlayers()
    GetGametime()
    Message1("Game ending...")
    wait(2)
    ReturnPlayers()
    RemoveMap()
end

1 comment

0

You made an unintended change for the asker. He is wondering why the while loop is not recognizing that there are more than two players in the game.

I suggest you split the condition from the while loop using the if statement, using else to display the message

--I have more code up here but not gonna paste because long code.
while true do
	if game.Players.NumPlayers < 2 then
    		Horn:Play()
  		  GetIntermission()
  		  Message1("Setting up game...")
		    Horn:Stop()
		    Announcment:Play()
 		   wait(2)
 		   Message2(" ")
		    GetMap()
 		   wait(1)
  		  GetPlayers()
 		   GetGametime()
  		  Message1("Game ending...")
 		   wait(2)
 		   ReturnPlayers()
 		   RemoveMap()

	else
		wait(.1)
		Message1("Needing 2+ players to start")
	end
end

2 comments

1

I think this may answer the question. Reason being is with game.Players.NumPlayers in the while loop, the while loop will terminate at the start of the game as there would only be one player. Separating the condition from the loop should fix the issue. However, now you have a forever running while loop without a wait. So you want to add a wait to keep the game from lagging out.

0

Oh ok forgot that, thanks!

Basically what you said is that you need 2 more or greater than 2 players to play. but when you use >= 2 it means there must be at least 2 players or more!

while game.Players.NumPlayers >= 2 do
    Horn:Play()
    GetIntermission()
    Message1("Setting up game...")
    Horn:Stop()
    Announcment:Play()
    wait(2)
    Message2(" ")
    GetMap()
    wait(1)
    GetPlayers()
    GetGametime()
    Message1("Game ending...")
    wait(2)
    ReturnPlayers()
    RemoveMap()
else
Message1('There must be at least 2 players to start!')
end


1 comment

0

elses only work in if then statements.

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