My NPC that I created isn’t jumping down platforms despite having the path computed fine, no clue why it’s doing this but I suspect that it has something to do with the if waypoints[nextWaypointIndex].Action == ...
parts but to be completely honest I have no idea.
Video -
Script -
if script.Parent.HumanoidRootPart:CanSetNetworkOwnership() then
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
end
--//--//--//--//--//--//--//-/-/-/--/-//---
local npc = script.Parent
local players = game:GetService("Players")
local pfs = game:GetService("PathfindingService")
local rs = game:GetService("RunService")
local path = pfs:CreatePath({
AgentHeight = 7,
AgentRadius = 4,
AgentCanJump = true,
Costs = {
Water = 100;
DangerZone = math.huge
}
})
local hum = npc.Humanoid
--/-/-/-//-//-/-/-/-/----/-//-/-///-/-/-//--/-/-/-/-/-
local attackAnim = Instance.new('Animation')
attackAnim.AnimationId = "rbxassetid://11949372195"
local attackTrack = script.Parent:WaitForChild("Humanoid"):LoadAnimation(attackAnim)
attackTrack.Looped = false
---/-/-/-/-/-//-/-/-///-/-//-/-///--//-/-//-/-//---/-/
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function findTarget()
local maxDistance = 300
local nearestTarget
for index, player in pairs(players:GetPlayers()) do
if player.Character then
local target = player.Character
local distance = (npc.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
local qdb = false
if distance <maxDistance then
nearestTarget = target
maxDistance = distance
end
--When Getting <5 to the player, the player takes damage
if distance <5 and not qdb then
nearestTarget.Humanoid:TakeDamage(0)
attackTrack:Play()
qdb = true
wait(.5)
qdb = false
end
end
end
return nearestTarget
end
local function followPath(destination)
local success, errorMessage = pcall(function()
path:ComputeAsync(npc.PrimaryPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = hum.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
hum:MoveTo(waypoints[nextWaypointIndex].Position)
if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2 --og 2
hum:MoveTo(waypoints[nextWaypointIndex].Position)
if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
else
warn("path not computed", errorMessage)
end
end
while wait() do
local target = findTarget()
if target then
--print(target.Name)
followPath(target.HumanoidRootPart.Position)
end
end