So I'm making a basic sword match script for my game.

The function below is supposed to update the match based on which team won. It runs when a team that is in the match dies. If two teams tie each other it runs the function below twice. Once for each team, and gives each team a win (If teams tie they're not supposed to get a win). It does this even though I have a wait before checking which teams are alive and checking if there's a tie.

-- This function runs each time a team that is part of the match dies. If a team ties, then it runs twice. One for each team.
function _match:Update(match, configurations)
	local teams = _match:GetTeamsFromMatch(match)
	local teamsAlive = _match:GetTeamsFromMatch(match)
	
	-- Check if teams are alive. 
	wait (1) 
	for index, team in next, teams	do
		local isTeamDead = _match:CheckIfTeamHasDied(team)
		if isTeamDead == true then
			print (team)
			table.remove(teamsAlive, index)
		end
	end
	
	-- Award win to team alive or no win if tie
	print (#teamsAlive)
	if #teamsAlive == 2 or #teamsAlive == 1 then
		if #teamsAlive == 2 then
			teamsAlive[1].Wins.Value = teamsAlive[1].Wins.Value + 1
			
			if teamsAlive[1].Wins.Value == match.Configuration.PlayTo.Value then
				_match:End(match, "Round has ended. "..teamsAlive[1].Name.." won!")
			end
		end
		
			-- reset arena
		for _, team in next, teams do
			for _, playerValue in next, team:GetChildren() do
				if playerValue:IsA("ObjectValue") and playerValue.Value and playerValue.Value:IsA("Player") then
					local player = playerValue.Value
					playerValue.IsDead.Value = false
					repeat wait() until player.Character and player.Character:WaitForChild("Humanoid").Health == player.Character:WaitForChild("Humanoid").MaxHealth
					player:LoadCharacter()
					wait()	
					local sword = serverStorage.LinkedSword:Clone()
					sword.Parent = player.Backpack
				end
			end
		end
			
		_match:TeleportTeams({teams[1], teams[2]}, match.Configuration.Map.Value)
	end
end

How can I fix this??

3 comments

0

You can check via boolean.

0

how exactly would you go about this?

0

I've tried checking several ways to make sure both players are dead, everything comes out true but it doesn't recognize it as true. What's the deal?