I am working on a Path Finding system using A*. I know it has been done before, but I this was a personal challenge for me to figure out and get working. However, I was working on a system of a “PathMap” which shows the nodes and connections. I’m using ObjectValues as a descendant of one node with the value of the ObjectValue being the other node to connect to. The following code is what I am currently using:
----- Create Connections -----
for _, node in pairs(dataMap:GetChildren()) do
--- This loop goes through all the connections to other nodes from "A" (All the B's from A)
for _, connection in pairs( node:GetChildren()) do
if node == connection.Value then
for _, allNodes in pairs(pathMap:GetChildren()) do
if allNodes.Name == node.Name then
allNodes.Color = Color3.fromRGB(42, 195, 200)
end
end
elseif node ~= connection.Value then
local hold = connection.Value
local newConnection = Instance.new("Part")
newConnection.Name = "Connector"
newConnection.Anchored = true
newConnection.TopSurface, newConnection.BottomSurface = Enum.SurfaceType.Smooth, Enum.SurfaceType.Smooth
newConnection.Color = Color3.fromRGB(151, 0, 0)
---This hold.Value is my problem
newConnection.Size = Vector3.new(0.45, 0.45, (node.Value - hold.Value).magnitude)
newConnection.CFrame = CFrame.new(node.Value:Lerp(hold.Value, 0.5), hold.Value)
newConnection.Transparency = 0.65
newConnection.Parent = pathMap
end
end
end
-----
Referring to the “hold.Value” comment in the code, the error has only happened twice and I don’t know why it happens. The only error code says something about unable to interpret nil from Value. That’s not the exact error message, but it tells me that the hold.Value is nil.
I know that it at least connects to the Object (node) because it never has given an error at local hold = connection.Value
.
If I get the error again I was get a screenshot or picture of it and upload it, but I’ve been trying for about half an hour and got nothing (I haven’t even changed the code). It will work 99.9% of the time, but I would rather fix the error than risk it. I have also checked the “dataMap” folder and each node in the folder to make sure that there are no nil ObjectValues. Last mention, I know the node.Value is not the problem (from the same error line). The nodes are Vector3Values and I also checked each node to make sure there is a Vector3 value.
[This code was copy and pasted so if there is an error from my own programming then that may have caused it, but I haven’t seen any problems and don’t have any errors from syntax]