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

Help with game.Players.NumPlayers?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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
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. M39a9am3R 3210 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

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. M39a9am3R 3210 — 7y
0
Oh ok forgot that, thanks! chill22518 145 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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


0
elses only work in if then statements. M39a9am3R 3210 — 7y

Answer this question