So basically, each person that joins the game gets an IntValue named "Playing" spawned inside them set to 0. Well, when my minigame thing initiates, everyone's 'Playing' value gets set to 1. Then when they die, it gets set back to 0.
What I need help figuring out is how would I find the amount of people who have their 'Playing' value set to 1? Below, you can see what I tried doing, but the third line isn't valid.
function onePersonLeft() for i, player in pairs(game.Players:GetPlayers()) do if #player.Playing.Value == 1 then return true else return false end end end
First, I agree with Legojoker: If you have a boolean value (is/is not) -- use a BoolValue!
Assuming you're using a BoolValue, you check if player
is currently playing like this:
if player.Playing.Value then
So we just need to find out for how many different player
s this is true:
local count = 0 for _, player in pairs( game.Players:GetPlayers() ) do if player.Playing.Value then count = count + 1 end end -- count is how many people are playing
If you care who (which players) are playing, instead of count
ing you can make a list:
local playing = {} for _, player in pairs( game.Players:GetPlayers() ) do if player.Playing.Value then table.insert(playing, player) -- add `player` to the list of `playing` people end end -- #playing is how many people are playing. -- playing[1], playing[2], ..., playing[#playing] are the people playing -- (in no particular order)