I’m making an NPC that constantly chases a part using PathfindingService, but he doesn’t want to perform the jump action and this is being a headache for me, that’s why I came here to ask for help!
- I looked in several posts, but none of them helped, they all say that you just need to check if the waypoint action is to jump and execute the jump action on the Humanoid, but I’VE ALREADY DONE THAT!
Any help will be appreciated! <3
Video:
robloxapp-20231230-1731429.wmv (2,0,MB)
Script:
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local ai = script.Parent
local target = ai.Target
local rig = ai.Parent
local human = rig:WaitForChild("Humanoid")
local hrp = rig.PrimaryPart or rig:WaitForChild("HumanoidRootPart")
hrp:SetNetworkOwner(nil)
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = true,
AgentCanClimb = true,
WaypointSpacing = math.huge,
Costs = {
Water = 24,
Climb = 4,
Danger = math.huge
}
})
local waypoints = {}
local waypoint: PathWaypoint
local function FollowPath()
if target.Value and target.Value:IsA("BasePart") then
local success, errorMessage = pcall(function()
path:ComputeAsync(hrp.Position, target.Value.Position)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
for _, w in pairs(waypoints) do
local newpart = Instance.new("Part")
newpart.Size = Vector3.new(0.35, 0.35, 0.35)
newpart.Anchored = true
newpart.CanCollide = false
newpart.Transparency = 0.5
newpart.Color = Color3.fromRGB(255, 255, 0)
newpart.Shape = Enum.PartType.Ball
newpart.Position = w.Position
newpart.Parent = workspace
Debris:AddItem(newpart, 0.05)
end
waypoint = waypoints[2]
if waypoint then
if waypoint.Action == Enum.PathWaypointAction.Jump then
human.Jump = true
end
human:MoveTo(waypoint.Position)
end
else
warn("Path not computed!", errorMessage)
end
end
end
RunService.Heartbeat:Connect(FollowPath)