API:Class/PathWaypoint/Action

Action

Read-only: This property can only be read from. Attempting to write to it will cause an error.
Property of Object blank Icon.pngPathWaypoint

Value Type: PathWaypointAction
Description: The Action property of a PathWaypoint shows what action a character would have to take in order to reach that waypoint. For most waypoints the action will be Walk, meaning a character can simply walk to this waypoint. In some cases, however, the action can be Jump, which means that the character has reached a ledge or a gap and will need to Jump to reach the next point.
Member redirect page does not exist - create it

Example

In this example, an NPC travels between two points, following paths created by PathfindingService. When following the path, the NPC looks at the Action of the waypoints it is trying to reach. If it encounters a waypoint it cannot get to by walking, the NPC’s Humanoid will be instructed to jump.

This code can be seen in action here. The place is not copy locked.

-- Make variables for Roblox services
local PathfindingService = game:GetService("PathfindingService")
 
-- Make variables for the NPC and some of its components
local wanderBot = game.Workspace.WanderBot
local rootPart = wanderBot.HumanoidRootPart
local humanoid = wanderBot.Humanoid
 
-- Make variables for the places the NPC will walk to
local goalA = game.Workspace.GoalA.Position
local goalB = game.Workspace.GoalB.Position
 
-- Function that moves the NPC to the passed in point
local function moveToPoint(point)
	-- Find a path to the destination and get the waypoints for the path
	local path = PathfindingService:FindPathAsync(rootPart.Position, point)
	local waypoints = path:GetWaypoints()
 
	-- Loop through all of the waypoints in the path
	for currentPoint = 1, #waypoints do
		-- Get the next waypoint to move to and move the humanoid towards it
		local waypoint = waypoints[currentPoint]
		humanoid:MoveTo(waypoint.Position)
 
		-- Check the action of the next waypoint. If it is a jump waypoint
		-- then make the NPC jump
		if waypoint.Action == Enum.PathWaypointAction.Jump then			humanoid.Jump = true
		end		
 
		-- Wait until the NPC has reached the next waypoint
		local reachedTarget = humanoid.MoveToFinished:Wait()
	end	
end
 
-- Move the NPC between the two points in a loop
while true do
	moveToPoint(goalA)
	wait(2)
	moveToPoint(goalB)
	wait(2)
end