im trying to make it so it’s last man standing and i have no idea where to start
I might misunderstood your question, but you can use collection service to determine if a player is alive or dead, then check all instances/players that has the “alive” tag, if the length of the table is 1, then it’s the last man standing
there are 2 different teams, the living team, and the dead team
You can get all players and filter out the dead teams (for loop or smth) instead of collectionservice
If you want a last man standing, then you need to check if the team has only one player left, you can do that by looping through the players, then if there’s only one, it will return true.
local team = --your team
local players = game:GetService("Players")
local function check()
local count = 0
local winner
for i, plr in pairs(players:GetChildren()) do
if plr.Team == team then
count +=1
winner = plr
end
end
if count == 1 then
return plr
end
return false
end
now whenever you want to check if there’s only one player in a team, just run the function in a if and then statement.
local winner = check()
if winner then
print("Winner is "..winner.."!")
end
you can run that function everytime someone dies, and gets removed from the “living” team.
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local team = teams.Team --Change to team's name.
local function lastPlayerStanding(bool : boolean)
if #team:GetPlayers() + 1 == #players:GetPlayers() then
return true
else
return false
end
end
Something like this?
You just need to check if there 1 player left on the living team, after each member change
local TeamPlayers = LivingTeam:GetPlayers()
if #TeamPlayers == 1 then
local LastPlayer = TeamPlayers[1]
end