Search code examples
luaroblox

Lua Roblox How to set spicific players health to 0


I am trying to make a game in Roblox that spawns every player onto a map and they have to try battle each other. However my problem is when the last player is left I don't know how to spawn him back in my lobby. I have all the players in the game stored in an array, once a person dies they are removed from the array. I have tried setting the last players health to 0 but whatever way the player is stored in the array it won't work with getting their humanoid.

This is my code so far:

if #plrs == 1 then
    plrs[1].Character.Humanoid.Health = 0
end

I am making my plrs array like this:

local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
    if player then
        table.insert(plrs,player) --Add each player to the Player array
    end
end

Thank you for any help.


Solution

  • Thank you everybody who tried to help.

    I figured out my own problem after a lot of research and reading back through my code.

    if #plrs == 1 then
        player.Character.Humanoid.Health = 0
    end