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

How do I check if only one value is true?

Asked by 5 years ago

I'm trying to make a round system and I need to know when one player is in the game so I can end it but I don't know how to check if only one player is in the game, But what I know is that I made a folder inside every player called PlayerValues and inside it there's a boolvalue that is called InGame.

THIS IS NOT A REQUEST, DO NOT FLAG THIS QUESTION.

I would really appreciate if you will help me, Plus I'll accept your question if it worked.

Thanks, MajinBluee

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

Use this:

function playersAlive()
       local amount = 0
       for _,v in pairs(game.Players:GetPlayers()) do
              if v.PlayerValues and v.PlayerValues.InGame and v.PlayerValues.InGame.Value then
                     amount = amount + 1
              end
       end
       return amount
end

-- Check if one player is alive

if playersAlive() <= 1 then
       print('Game over')
end
0
EXPLAIN THE ANSWER! M39a9am3R 3210 — 5y
0
You don't need to. I already know what your doing. MajinBluee 80 — 5y
Ad

Answer this question