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

Winner Script? Help?

Asked by
C600R 0
8 years ago

I'm making this sword fighting game and I wan't to know how to make a script where, when everyone dies except one person, the round ends and everyone goes back to the lobby and the winner gets 15 exp. I already did the exp script, when you die or atleast play a round you get 10 exp. But when everyone dies, the round still goes on, I need help please. Thanks -C600R

0
This is not a request site. iFlusters 355 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

Checking for survivors

In order to check for survivors, you have to assume that you know who was playing in the first place. When you start a round, add all of the players to the table. When they die, remove them and check if anyone is still alive. If nobody is still alive, end the round.

Example implementation

local alive,check = {};
local function aggr() -- Called at the start of a round
    for k,v in next, game.Players:GetPlayers() do -- For every player in the game
        if v.Character and v.Character.Humanoid.Health > 0 then -- If they are alive
            alive[v] = true; -- Remember them
            v.Character.Humanoid.Died:connect(function() -- When they die,
                alive[v] = nil -- Forget them.
                check() -- Check if everyone is dead
            end);
        end;
    end;
end;
check = function()
    if not next(aggr) then
        -- Everyone is dead, it's the end of the world!
        -- You can end your round now. 
        -- Just make sure you have some sort of scheduler or listener to end it with.
    end;
end;
Ad

Answer this question