Help on team remove player

I need help with a problem, in my code I have a TemporizadorEvent event

that when it is activated it should check the teams with a current list, the problem is that whenever the event is triggered it returns the old value of the list, there are no more players in the list but it returns the number of players, I need something to clean or update, does anyone know how?

IGNORE The finishEvent, everything is working perfectly, the problem is in the timeEvent.Onserver

local Team1 = game.Teams:WaitForChild('A')
local Team2 = game.Teams:WaitForChild('B')
local Team3 = game.Teams:WaitForChild("select")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeEvent = ReplicatedStorage:WaitForChild("timeEvent")
local finish = ReplicatedStorage:WaitForChild("finish")
local online = false
local playersteam1
local playersteam2

local function veifyTeams()

	print(playersteam1)
	playersteam1 = #game.Teams['A']:GetPlayers()
	playersteam2 = #game.Teams['B']:GetPlayers()
	print(playersteam1)
	if playersteam1 == 1  and playersteam2 == 0 then
		if not online then

			timeEvent:FireAllClients()
			online = true
		end
		return true
	else
		return false
	end
end
while wait(1) do
	if not online then
		print("loading")
		if veifyTeams() then
			break
		end
	end
end

Team1.PlayerAdded:Connect(veifyTeams)
Team1.PlayerRemoved:Connect(veifyTeams)
Team2.PlayerAdded:Connect(veifyTeams)
Team2.PlayerRemoved:Connect(veifyTeams)

finish.OnServerEvent:Connect(function()
	local players = game:GetService("Players")
	players.PlayerAdded:Connect(function(player)
		finish:FireClient(player)
	end)
end)

timeEvent.OnServerEvent:Connect(function()
	online = false
	veifyTeams()	
end)```
1 Like