Hello, everyone.
I have an npc that sometimes plays its running animation, but sometimes just slides.
To apply the animations to the npc, I just took Roblox’s Animate script and changed the animation ids.
The below is my pathfinder script for the npc. There shouldn’t be anything wrong with this.
char = script.Parent
local npc = script.Parent
local hrpOfNPC = npc:WaitForChild("HumanoidRootPart")
pathFinder = game:GetService("PathfindingService")
path = pathFinder:CreatePath()
local Players = game:GetService("Players")
local position = workspace.temppart.Position
local target = game.Workspace:WaitForChild("coolguyweir")
while wait() do
local plrs = game.Players:GetPlayers()
local closestHRP
for i, plr in pairs(plrs) do
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character.Humanoid.Health > 0 then
local hrp = plr.Character.HumanoidRootPart
local distanceBetween = (hrpOfNPC.Position - hrp.Position).Magnitude
if not closestHRP then
closestHRP = hrp
end
if (hrpOfNPC.Position - closestHRP.Position).Magnitude < distanceBetween then
closestHRP = hrp
end
end
end
npc.Humanoid:MoveTo(closestHRP.Position)
end
Can someone please please help me fix this? It’s been bothering me a lot.
Thanks!
-coolguyweir
1 Like
I made something just like this and this is the script that worked for me;
Now obviously you would need to change this to fit you but this is my script. This is a server script inside of the npc not the humanoid, and the animations are inside of the script.
local AnimTrack = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation)
local AnimTrack2 = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation2)
local AnimTrack3 = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation3)
--Walk Anim
script.Parent.Humanoid.Running:Connect(function(speed)
if speed > 0 and not AnimTrack.IsPlaying then
AnimTrack:Play()
elseif speed == 0 and AnimTrack.IsPlaying then
AnimTrack:Stop()
end
end)
--Shield Up Anim
game.Workspace.Village.Agro.Touched:Connect(function(hit)
if hit.Parent.Name ~= "Barbarian" and hit.Parent.Name ~= "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if not AnimTrack2.IsPlaying then
AnimTrack2:Play()
end
end
end)
game.Workspace.Village.StopAgro.Touched:Connect(function(hit)
if hit.Parent.Name ~= "Barbarian" and hit.Parent.Name ~= "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if AnimTrack2.IsPlaying then
AnimTrack2:Stop()
end
end
end)
--Swing Anim
local Cooldown = 1
local debounce = false
script.Parent.SwingDist.Touched:Connect(function(hit)
if hit.Parent.Name ~= "Barbarian" and hit.Parent.Name ~= "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if not AnimTrack3.IsPlaying and not debounce then
debounce = true
script.Parent.Hitting.Value = true
AnimTrack2:Stop()
AnimTrack3:Play()
elseif not AnimTrack3.IsPlaying and debounce then
script.Parent.Hitting.Value = false
AnimTrack2:Play()
wait(Cooldown)
debounce = false
end
end
end)
can I insert the animation link for :load animation?
Usually you would just use Humanoid.Animator:LoadAimation(--The animation)
But you could try doing Humanoid.Animator:LoadAimation("YOUR ANIMATION HERE".AnimationId)
I don’t know of a way that you could just load an animation from an id.
mk. I’m applying all anims and will let you know if this works shortly!
1 Like
how would I go about implementing a jump function…
You would simply add;
Humanoid.Jumping:Connect(function() --replace "Humanoid" with your variable for Humanoid.
--jumping animation plays here
end)
I won’t be able to help anymore to day after this post.
btw, you load the animations. I have a question: Are animations the ones with the little blue icon, or the ones with a reels icon?
Animations have a photo real icon.