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.
I found a way by adding a brick to the playzone but i feel like it will easily break the game. That’s why i don’t want to use this method to get the last player of the following team.
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
I want it so an event fires when there is one player in the contestant team, then i will team them “Fallen”, set their health to 0, and add a win to their leaderstats
How can i remove a player name’s string from the following table? I have tried but it says I need to remove numberwised player. So how can i find the player name string from the table and remove them?
oh wait are you talking about getplayers? if so simply use table.remove(team, player.Name) or just remove the player. whichever one is best and works for your code
local PlayersPlaying = {}
for i, v in pairs(game.Players:GetChildren()) do
table.insert(PlayersPlaying, i, v.Name)
end
And checking the number of players once the LoseBrick is touched.
game.Workspace.Lobby.TeamChanger.Touched:Connect(function(hit)
table.remove(PlayersPlaying, hit.Parent.Name)
if #PlayersPlaying <= 1 then
SendMessage(tostring(PlayersPlaying[1]).. " has won the game!")
wait(5)
end
end)