Help with pathfinding

Ok, so im trying connect waypoints with beams but its weird.

for _, waypoint in pairs(waypoints) do
		local part = Instance.new("Part")
		if lel == 0 then
			lel = 1
			attachement1 = Instance.new("Attachment",part)
		elseif lel == 1 then
			lel = 2
			attachement2 = Instance.new("Attachment",part)
			local beam = Instance.new("Beam",part)
			beam.Attachment0 = attachement1
			beam.Attachment1 = attachement2
		elseif lel == 2 then
			lel = 0
			attachement1 = Instance.new("Attachment",part)
			local beam = Instance.new("Beam",part)
			beam.Attachment0 = attachement1
			beam.Attachment1 = attachement2
		end
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Color = color
		part.Size = Vector3.new(0.6, 0.6, 0.6)
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace
	end
end