DarkRP Mayor Demote and Promote Vice


function MayorDemote( victim, weapon, killer )
    if victim:Team() == TEAM_MAYOR then
        victim:ChangeTeam(TEAM_CITIZEN, true)
        victim:ChatPrint("You were killed and have lost mayor.")
        killer:AddMoney(500)
        for k, v in pairs (player.GetAll()) do
            if v != victim then
                v:Notify( 0, 4, "The mayor has been murdered!" )
if v:Team() == TEAM_VICE then v:ChangeTeam( TEAM_MAYOR, true )
            end
        end
    end
end
hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )


This code is suppost to happen when the mayor dies, he is demoted to citizen. Then, the killer gets $500 and the Vice Mayor is suppost to get promoted to Mayor…

But it seems to break when the loop that checks for Vice mayor happens… how can this be fixed?

You are missing an end.
[lua]
function MayorDemote( victim, weapon, killer )

if victim:Team() == TEAM_MAYOR then
	
	victim:ChangeTeam(TEAM_CITIZEN, true)
	victim:ChatPrint("You were killed and have lost mayor.")
	killer:AddMoney(500)
		
	for k, v in pairs (player.GetAll()) do
		
		if v != victim then

			v:Notify( 0, 4, "The mayor has been murdered!" )
				
			if v:Team() == TEAM_VICE then
					
				v:ChangeTeam( TEAM_MAYOR, true )
					
			end -- This is the end you missed.
				
		end
			
	end
		
end

end
hook.Add( “PlayerDeath”, “mayorDemote”, MayorDemote )
[/lua]

-snip-