Hello, So i have a minigame styled game and I need to figure out how to create a script to know when everyone leaves an area, so it can basically end the game. I had an idea of a way to do this by creating a boolvalue inside of the player and then making it true when the player exits the area (the area is just an invisible cancollide false part engulfing the entire space) and then a masterscript that can find the number of players in the game and basically know at all times if there is anyone inside of the area, and once no one is in it the game ends.
So basically, I think I got the masterscript covered, besides the part where it counts the amount of players in the game. Also it would need to be actively updated every round to know if the amount of players changes. I need some starting help to even begin to understand how to count the players. I do have the boolvalue injector though.
game.Players.PlayerAdded:connect(function(plr) local FinishedValue = Instance.new('BoolValue', plr) FinishedValue.Name = 'FinishedValue' end)
Thank you for reading, if this sounds like a request, please let me know in the replies so I can somehow word it differently.
I think there is a better way than this. You can check if any of the players are inside the area by using their Vectors
AreaPosition = --Get the position of the floor of the area AreaSize = --Get the size of the floor of the area local function check() local count = 0 --Will increase if the script finds a plr in the area for _, plr in pairs(game.Player:GetChildren()) do --For every player in the game local PlrPos = plr.Character.HumanoidRootPart.Position if PlrPos.X < AreaPosition.X + (AreaSize.X/2) and PlrPos.X > AreaPosition.X - (AreaSize.X/2) and PlrPos.Y < AreaPosition.Y + (AreaSize.X/2) and PlrPos.Y > AreaPosition.Y - (AreaSize.X/2) then --If their character is inside the area count = count + 1 end end return count --return amount of players in the area end local PlayersInTheArea = check()