Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I end a match of something after all players but one are dead?

Asked by 9 years ago

Please help.

The way I want it to be like (does not have to be like this!) Once players are teleported somewhere then they die, and there is one player left touching some bricks then the script should teleport the player back.

1 answer

Log in to vote
2
Answered by
DataStore 530 Moderation Voter
9 years ago

Quite easily, really.

One way you could accomplish this is by adding all players to a table upon the match beginning, as well as connecting a Died event with each of their Humanoids. When one of them dies, you remove them from the table (or otherwise tag them). When the table has nobody left, you end the match. If the table only has one person remaining, you end the match with your winner.

Below is an example of how you would add every player to a table, as well as remove them from the table upon their death.

local InGame = {}

function Find(Item, Table, Remove)
    for i, v in pairs(Table) do
        if v == Item then
            return Remove and table.remove(Table, i) or Item 
        end
    end
end

for _, Player in pairs(game.Players:GetPlayers()) do
    if Player.Character and Player.Character:FindFirstChild("Humanoid") then
        InGame[#InGame +1] = Player
        Player.Character.Humanoid.Died:connect(function()
            Find(Player, InGame, true) 
        end)
    end
end
0
Thanks a lot DataStore! apolodorerou 0 — 9y
Ad

Answer this question