Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Winner Script? Help?

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

1 comment

0

This is not a request site.

1 answer

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;

This discussion is preserved as it was. New answers, comments, and votes are closed.