Hello! For my next game I’m trying to detect when only one player remains alive in a match. How do I do that? (I’m very new to scripting)
Note: Sorry for how short this topic is, I don’t know what else to write.
Hello! For my next game I’m trying to detect when only one player remains alive in a match. How do I do that? (I’m very new to scripting)
Note: Sorry for how short this topic is, I don’t know what else to write.
You can check the amount of players in the server like so:
print(#game.Players:GetPlayers())
Alternatively if you want to loop through each player you can do:
for i, v in pairs(game.Players:GetPlayers()) do
print(v)
end
We can use these methods to check a players health:
local Alive = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character.Humanoid.Health > 0 then
table.insert(Alive, v)
end
end
print(Alive)
You can also do this in reverse like so using .Died:
for i, v in pairs(game.Players:GetPlayers()) do
v.Character.Humanoid.Died:Connect(function()
print(v.Name.. " has died.")
end)
end
Thanks for the in depth response! That’s definitely gonna help me out a lot.