I posted about this earlier and I got some help that was partially useful. The script I'm trying to fix is one that waits 5 seconds and then selects 2 random players and teleports them to different spawns. The problem is that the script doesn't call the function when it's supposed to, and I'm not getting an error message.

function sortTeams()
		local PlayersTable = game.Teams.Spectating:GetPlayers()
		
		local RandomPlayer = PlayersTable[math.random(#PlayersTable)]
		
		local PlayerChar = RandomPlayer.Character
		
		if (PlayerChar and PlayerChar:FindFirstChild('HumanoidRootPart')) then
    		PlayerChar.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(239.9, 5.962, 228.2))
		end
		
		
		local RandomPlayerTwo = PlayersTable[math.random(#PlayersTable)]
		
		local PlayerCharTwo = RandomPlayerTwo.Character

		if (PlayerCharTwo and PlayerCharTwo:FindFirstChild('HumanoidRootPart')) then
    		PlayerCharTwo.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(118.9, 5.962, 196.2))
		end
		
	end
	
while (#game.Players:GetPlayers() >= 2) do
    wait(5)--intermission
    sortTeams()
end

thanks for the help!