I have a leaderstats value called "Banked". Players on a team bank their coins, and when both teams have banked, whichever team has the most coins banked wins the round. How could I do this?

This is my current attempt, but the team that banked their coins last will always show as 0 coins banked.

for i, v in pairs(Players:GetPlayers()) do
		if v.Team == Teams.Blue then
			totals[1] = totals[1] + v.leaderstats.Banked.Value
		elseif v.Team == Teams.Red then
			totals[2] = totals[2] + v.leaderstats.Banked.Value
		end
		wait(1)
		v.Team = Teams.Waiting
		v.leaderstats.Coins.Value = 0
		wait()
		if totals[1] > totals[2] then
			print("Blue won")
			showNotification:FireAllClients("Blue won!", Color3.new(0, 0, 1), 5)
		elseif totals[2] > totals[1] then
			print("Red won")
			showNotification:FireAllClients("Red won!", Color3.new(0.870588, 0, 0), 5)
		else
			print("Tie")
			showNotification:FireAllClients("Tie!", Color3.new(0, 0, 0), 5)
		end

2 comments

0

Line 2: Try using v.TeamColor and Teams.Blue.TeamColor instead of v.Team and Teams.Blue

0

It does the same thing. I don't think detecting the teams is the problem, it's that it doesn't update the last team when they bank their coins