local Pathfinding = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local path = Pathfinding:CreatePath({
AgentHeight = 4;
AgentRadius = 2;
AgentCanJump = true;
Costs = {
Water = 100;
DangerZone = math.huge
}
})
local Character = script.Parent
local humanoid = Character:WaitForChild("Humanoid")
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function findTarget()
local maxDistance = 200
local nearestTarget
for index, player in pairs(Players:GetPlayers()) do
if player.Character then
local target = player.Character
local distance = (Character.HumanoidRootPart.Position - target.HumanoidRootPart.Position) .Magnitude
if distance < maxDistance and target.Humanoid.Health > 0 then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function onTouch(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local hum = hit.Parent.Humanoid
hum.Health -= Character.Configuration:GetAttribute("Damage")
end
end
local function followPath(destination)
local success, errorMessage = pcall(function()
path:ComputeAsync(Character.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 = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
humanoid:MoveTo(waypoints[nextWaypointIndex] .Position)
if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid.MoveToFinished:Wait()
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex] .Position)
else
humanoid:MoveTo(destination)
end
end
local npcRootPart = Character.HumanoidRootPart
npcRootPart:SetNetworkOwner(nil)
Character.Torso.Touched:Connect(onTouch)
local jump
local run
local walk
local idle
function LoadAnimations()
local Animator = humanoid.Animator
local Animations = Character.Animate
run = Animator:LoadAnimation(Animations.run.RunAnim)
walk = Animator:LoadAnimation(Animations.walk.WalkAnim)
idle = Animator:LoadAnimation(Animations.idle.Animation1)
jump = Animator:LoadAnimation(Animations.jump.JumpAnim)
run.Looped = true
walk.Looped = true
jump.Looped = true
idle.Looped = true
end
LoadAnimations()
humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Running then
if Character.Torso.AssemblyLinearVelocity.Magnitude > 10 then
run:Play()
else
walk:Play()
end
elseif new == Enum.HumanoidStateType.Jumping then
jump:Play()
elseif Character.Torso.AssemblyLinearVelocity.Magnitude < 1 then
idle:Play()
end
end)
while wait() do
local target = findTarget()
if target then
followPath(target.HumanoidRootPart.Position)
end
end```
The humanoid doesnt jump why???