My code is supposed to create three teams, give them all an anti-tk sword, and then when I click it again it's supposed to change the teams of the people in the three teams to "Trainees" and delete the teams. Currently the script creates the teams, gives the players in the teams swords (With help from another script) And then deletes the teams when I click it again. It does not, however, create the teams again after the first pair of clicks or change the teams of or respawn the players in the three teams. If you could help me out that would be great!

button = script.Parent

local on = false

function clicked()
	if (on == false) then
		local team1 = Instance.new("Team")
		team1.Name = "Spectators"
		team1.Parent = game.Teams
		team1.AutoAssignable = false
		team1.TeamColor = BrickColor.new ("Institutional white")
		
		local team2 = Instance.new("Team")
		team2.Name = "GreenTeam"
		team2.Parent = game.Teams
		team2.AutoAssignable = false
		team2.TeamColor = BrickColor.new ("Earth green")
		local sword = game.Lighting.atk
		sword:clone()
		sword.Parent = game.Teams.GreenTeam
		
		local team3 = Instance.new("Team")
		team3.Name = "PurpleTeam"
		team3.Parent = game.Teams
		team3.AutoAssignable = false
		team3.TeamColor = BrickColor.new ("Royal purple")
		sword:clone()
		sword.Parent = game.Teams.PurpleTeam
		on = true
	elseif (on == true) then


		game.Teams.Spectators:remove()
		game.Teams.GreenTeam:remove()
		game.Teams.PurpleTeam:remove()
		game.Teams.GreenTeam.atk:remove()
		game.Teams.PurpleTeam.atk:remove()
		on = false
	end
end


script.Parent.MouseButton1Click:connect(function(a) clicked() end)