Ok so, this is quite hard to explain but I have two teams, each with 2 players on each team. When 1 player dies it sets a bool for that player to true (to show they are dead). It then calls a function which checks if all players on one of the teams are dead. If not, nothing happens, if they are all dead then it runs some code. My issue is that if both players on one of the teams die at very similar times, the function gets ran twice. Any Ideas how I could fix this?
local function checkDeaths()
-- Checks that one whole team is dead
if T1Player1Dead == true and T1Player2Dead == true then
-- Normally some code here that runs
-- Functions that check when a player dies
if T1Player1 then
table.insert(connections, T1Player1.CharacterRemoving:Connect(function(hit)
T1Player1Dead = true
checkDeaths()
end))
end
if T1Player2 then
table.insert(connections, T1Player2.CharacterRemoving:Connect(function(hit)
T1Player2Dead = true
checkDeaths()
end))
end
Iād really appreciate any help, cheers