I'm making a game where your team tries to get the most kills between a time limit. How would I do that?
✓ ANSWER ACCEPTED
How do I make a match timer for a fighting game?
1 answer
✓ Accepted answer
First up, I recommend using a _G.playersAlive = {} variable. This makes it accessible anywhere. In one script you could do this:
_G.playersAlive = {}
local matchTime = 60 -- In seconds
local plrs = game.Players:GetChildren() -- Sets up a table filled with players
for i,v in pairs(plrs) do
table.insert(_G.PlayersAlive, v.Name) -- Adds in all the players into the table
end
for i=1,matchTime do -- Sets up a loop that will run 60 times (that's the matchTime above).
if #_G.PlayersAlive == 1 or #_G.PlayersAlive == 0 then -- Checks to see if the # of things in _G.PlayersAlive = 1 or 0
break -- If _G.PlayersAlive has 0 things in it, it breaks the loop and continues running the next piece of code.
elseif #_G.PlayersAlive >= 2 then -- If the # of things in _G.PlayersAlive greater than or equal to 2 next line of code is run
wait(1) -- Waits one second
end
end
-- Down here you can add code for after the match timer ends
Code to detect if only one player is alive:
game.Players.PlayerAdded:connect(function(plr) -- Fires when the player joins the game
plr.Character.Humanoid.Died:connect(function() -- Fires when the player dies
for i,v in pairs(_G.PlayersAlive) do -- Sets up a for index,value loop
if v == plr.Name then -- Checks to see if the current value in the table is equal to the name of the player.
table.remove(_G.PlayersAlive, i) -- Removes the player from the table when the player dies
end
end
end)
end)
Hope I helped! :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Look at the humanoid.died event.
This really isn't specific. Match timer and team kills doesn't have the same meaning. Also I would suggest reading the wiki before asking here. It answers most of these basic questions.