So, I'm working on a game, where, if you lose. You basically change team. Last one to be in the Contestants team wins. However, I'm having issue on detecting the last person on the Contestant team and award them a win, and teaming them to "Fallen". I could make a script to count the number of players though. Here is what i tried:
local team = game:GetService("Teams").Contestants local players = team:GetPlayers() if #players <= 1 then game.ServerStorage.WinDetector:Clone().Parent = game.Workspace end if #players == 0 then SendMessage("Couldn't detect a winner.") EndGame() end
Your if
statements only check once because they're not in a loop. I suggest using the line each time someone gets moved, like so:
Player:MoveToTeam("Fallen") -- the line where the player changes team if #players == 1 then -- the line where you check the amount of players game.ServerStorage.WinDetector:Clone().Parent = game.Workspace elseif #players == 0 then SendMessage("Couldn't detect a winner.") EndGame() end
I have fixed the issue by using Tables. You can get help from this post: https://devforum.roblox.com/t/how-do-i-get-the-last-player-in-a-team/876576/ Thank you all for helping.
For me, I would check all of the players to see if the players are in the Fallen team. I have made a script that checks that. (Mark this answered if this is what you need)
--Variables TeamName = game.Teams.Fallen --team name PlayersOnFallen = 0 --sets the variable to 0 --main part of the script for i,v in pairs(game.Players:GetPlayers()) do --goes through all the players (game.Players) if v.Team == TeamName then --if player is on the fallen team then, PlayersOnFallen = PlayersOnFallen + 1 --adds 1 to the variables end end print(PlayersOnFallen) --prints out how much player(s) are on the team if PlayersOnFallen == 1 then --if there's 1 player on the Fallen team then, game.ServerStorage.WinDetector:Clone().Parent = game.Workspace --clones the win detector else print("There still isn't 1 player on the Team Fallen") end