Npc goes only to 4 waypoints and then skips to the end

Can I suggest just doing a print(waypoints) after you have defined. Just because you have numbered them does not mean that they will appear in numerical order in the table. If you want them to be defined numerically, I’d recommend pre-populating the table:

local waypoints = {bruh.Waypoints.1, bruh.Waypoints.2, bruh.Waypoints.3, bruh.Waypoints.4}

That might work, but no guarantee that when you run through them as ipairs they will not get messed up again, so the other alternative would be to define them with an index:

local waypoints = {
[1] = bruh.Waypoints.1,
[2] = bruh.Waypoints.2,
[3] = bruh.Waypoints.3,
[4] = bruh.Waypoints.4}

they all go in order.
idk why it breaks.

for i, v in ipairs(waypoints) do
	print("WP:", i, "Pos:", v)

OK, so at this point I would go right back to basics and verify that what you expect to happen is actually happening.

Add a print statement in to the start of the for loop, and print the index and value pair and check each one against it’s expected values.

By doing a play test, you can also see how long each change interval takes. This might show you something unexpected.

em
em

strange results.

Is that 2 consecutive tests? If it is then see my first answer. When you do the GetChildren, they are not always guaranteed to be in the order in which they appear in the Explorer pane in Sutudio.

I’d suggest using the second method of defining the index for each waypoint and iterating through them that way.

half of the maps have multiple waypoints, i dont think that would be a very good idea, but hey what if i use number check.

OK, you could use tonumber() to convert the part name into an numerical value, then manually insert them to the table at the correct index position, obviously including an edge case check for “end”.

and how is that though?

woaaahh

i fixed it myself, turns out i wasnt doing it correctly.

Its literally moving across straight lines. Pathfinding Service isnt going to do anything.

It’s late and I would make a mess of that at the moment. Essentially, you need multiple tables:

local waypoints = bruh.Waypoints:GetChildren() -- The waypoints
local waypointNames = {} --The numerical value of the waypoints name  

-- Build WaypointName & Index tables
for index, part in ipairs(waypoints) do
	table.insert(waypointNames , tonumber(part.Name))
end

-- Sort table by Waypoint Name value
table.sort(waypointNames )

-- Iterate thru waypoints now in numerical part name order
for index, part in  ipairs(waypointNames ) do
	local vpos = bruh.Waypoints:FindFirstChild(part).Position + Vector3.new(0, 2.93, 0) -- your parts position
-- the rest of your code checks
end

I think that will work. I went thru numerous revisions and the above seems quick and dirty

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.