im currently on a topic where i made a Pathfinding Link inside my Walkway Model for NPCs to use.
The NPCs find the link without problems. The only thing i cant come up with is how i can retrieve the model where the pathfinding link is located → e.g. the exact walkway model they are using:
for i = 1, #waypoints do
local waypoint = waypoints[i]
Humanoid:MoveTo(waypoint.Position)
local result = Humanoid.MoveToFinished:Wait()
if not result then
break
end
if waypoint.Action == Enum.PathWaypointAction.Custom then
if waypoint.Label == "MovingWalkway" then
local walkwaymodel = ??
...
task.wait(5)
end
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
Since its a tycoon game and the walkway is dynamically built i cant access it through the workspace.Walkway… .
An idea was to loop trough descendants of workspace and compare the waypoint.Position but thats extremely unefficient.
Sorry, I’m not completely clear on the structure of your data, so I’ll make some guesses and hopefully something fits:
You seem to be able to find the Pathfinding Link, which is inside the model you want - can you not find the Model by looking at the PathfindingLink.Parent?
When you create walkway that has this Pathfinding Link associated with it, you could add this to a table that you can then use as a lookup later.
Can you describe how you create the Pathfinding Link and the Walkway Model and their structure within you workspace?
The Pathfinding only recognizes the Pathfinding Link and creates a Waypoint based on this. So i only have wayoint and waypoint.Label available. Based on the Label i know that the NPC that uses the Waypoint is currently using the Walkway:
if waypoint.Action == Enum.PathWaypointAction.Custom then
if waypoint.Label == "MovingWalkway" then
local walkwaymodel = ??
...
task.wait(5)
end
end
Heres a screenshot of the Pathfinding Link inside the Walkway model.
So for your first idea: It wouldnt work because of the situation above.
For your second idea: I dont exactly know how to this would work since we could save the Link when the Walkway is built… but how can i check if the Link is the correct one with only waypoint and waypoint.Label?
I hope you get what i mean. If not then i will clarify it further.
I have to admit I don’t have great knowledge on this and if someone who knows more wants to add something, they would be more than welcome.
If I look at PathfindingLink documentation I see it has a property Label which is automatically included in the waypoint that is generated. So you know the model the Pathfinding Link is built into and you can add a label which is added to the waypoint. Is it not possible to make the label sufficiently unique that you can look up the model from it?
I’m imagining that you give each model a unique name and set that as the PathfindingLink label?
Yeah we have the Label. But if we adapt your idea we would end up with literally infinite different If checks since each Label needs to be unique which isn´t really worth implementing in the first place.
if waypoint.Label == "MovingWalkway1" then
local walkwaymodel = ??
...
task.wait(5)
elseif waypoint.Label == ""MovingWalkway2" then
...
elseif ...
...
end
I already read the Pathfinding Documentation but they also just used
local boat = workspace.Boat
to access the Boat e.g. model.
I asked AI aswell but it cant come up with a reasonable solution.
I guess the Position is the only thing we could maybe use to look for the model
We simulate the NPC using the Walkway with Tweenservice:
local waypointAfter = waypoints[i+1]
if waypointAfter and waypointAfter.Action == Enum.PathWaypointAction.Custom then
if waypointAfter.Label == "MovingWalkway" then
local goal = {Position = waypoints[i+2].Position + Vector3.new(0, 2.5, 0)}
local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear)
local tween = TweenService:Create(HumanoidRootPart, tweenInfo, goal)
task.wait(0.5)
tween:Play()
tween.Completed:Wait()
end
end
With this approach we dont need to get the model at all!
Just for reference, instead of getting into the mess of hard coding “else if” conditionals what I was proposing was this type of logic:
local model1 = workspace:WaitForChild("Model_1")
local model2 = workspace:WaitForChild("Model_2")
local modelsTable = {}
modelsTable["label_1"] = model1
modelsTable["label_2"] = model2
print("label_2 points to:", modelsTable.label_2.Name)
local myLabel = "label_1"
print("myLabel points to:", modelsTable[myLabel].Name)
So you add and remove reference to the table as you need (during model creation code or in studio) then you can just use the table to give you a reference from the label to the model directly.