Drawing a line between two point error

I’m trying to connect two points (nodes) with a line, and all goes well UNTIL number 9 needs to connect to 10, instead it connects 8 to 10 and continues to do that forever. I have zero clue why… like ZERO clue. I’ve rewritten it about 4-5 times and same thing. I believe it might be in the segment function, but :shrug:.

Heres my script with non-important things cut out to save your eyes

local module = function(plr, toggle)
	local function makeSegment(a, b)
		print(a.Name, b.Name)
		local segment = Instance.new("Part")
		segment.Parent = a
		segment.Name = "Segment"
		segment.Anchored = true
		segment.CanCollide = false
		local Center = (a.Position + b.Position) / 2
		segment.CFrame = CFrame.new(Center, a.Position)
		segment.Color = Color3.fromRGB(66, 3, 255)
		segment.Material = Enum.Material.Neon
		segment.Size = Vector3.new(1, 1, (a.Position - b.Position).Magnitude)
	end
	local function findHighestNumber(place)
		local highest = nil

		for _, value in pairs(place:GetChildren()) do
			if not highest then
				highest = value.Name
				continue
			end

			if value.Name > highest then
				highest = value.Name
			end
		end
		return tonumber(highest)
	end
	local function findLowestNumber(place)
		local lowest = nil

		for _, value in pairs(place:GetChildren()) do
			if not lowest then
				lowest = value.Name
				continue
			end

			if value.Name < lowest then
				lowest = value.Name
			end
		end
		return tonumber(lowest)
	end
	local plrPath = workspace.PlayerPaths[plr.Name.."_path"]
	if toggle == true and char then
		enabled = true
		while true do
			if enabled == true then
				if Humanoid.MoveDirection ~= Vector3.new(0,0,0) then -- if theyre walking, continue
					if #plrPath:GetChildren() == 0 then -- if the amount of nodes is 0 make one named "1"
						local newName = findHighestNumber(plrPath) or 1
						local newNode = Instance.new('Part')
						newNode.Parent = plrPath
						newNode.Anchored = true
						newNode.CanCollide = false
						newNode.CFrame = HRP.CFrame
						newNode.Transparency = 1
						newNode.Size = Vector3.new(.1,.1,.1)
						newNode.Name = newName
					else
						local newName = findHighestNumber(plrPath)+1
						local newNode = Instance.new('Part')
						newNode.Parent = plrPath
						newNode.Anchored = true
						newNode.CanCollide = false
						newNode.CFrame = HRP.CFrame
						newNode.Transparency = 1
						newNode.Size = Vector3.new(.1,.1,.1)
						newNode.Name = newName
						makeSegment(plrPath[findHighestNumber(plrPath)-1], newNode)
					end
				end
			else
				break
			end
			wait(.25)
		end
	end
end


return module

You are comparing strings are greater than another. Set both value.Name and highest to tonumber()

1 Like

Same issue will occur here if not changed.

1 Like

Wow! I didn’t know that had an effect on anything, or would cause a problem like this. thank you!