my npc for some reason when being told to move with the player’s humanoid velocity will lose it’s run animation, and it’ll rarely randomly play for a couple of seconds : /
every other animation works perfectly fine as well, which confuses me!
the animation priority is “Movement” and I have tried “Action”, but to no avail!
here is the code as well!
local rotation
local movement
local target
function events.mimic(plr: BasePart)
if plr then
target = plr
if not rotation and not movement then
local plrhum = plr.Parent:FindFirstChildOfClass("Humanoid")
rotation = runservice.Heartbeat:Connect(function()
alignor.CFrame = CFrame.lookAt(root.Position, Vector3.new(target.Position.X,root.Position.Y,target.Position.Z))
end)
if plrhum then
movement = plrhum.Changed:Connect(function(prop)
if prop == "MoveDirection" then
hum:Move(-plrhum:GetMoveVelocity())
elseif prop == "Jump" then
local s = hum:GetState()
if s ~= Enum.HumanoidStateType.Freefall and s ~= Enum.HumanoidStateType.Jumping then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
end)
end
else
movement:Disconnect()
rotation:Disconnect()
end
end
end
interesting bcs when i made my mobs ai i played the animations manualy and when i didnt play them they didnt play from the animator script. so maybe add a print debug in the roblox animate script and see if it plays the run animation.
if not just play the animation manualy after u do hum:walkto()
it does indeed print! so it’s 100% going through! but I feel like it’s rhetorical to play the run animation via the script that I’m running the mimic function in as every other animation works fine : /
side note the animation does indeed play when not forcing it to mimic the player
maybe bcs the move() get called repeatedly but other events like :changestate() get called once. idk try to make the run animation play manualy and tell me if it work
it shouldn’t get called repeatedly, only when the player changes direction. if I don’t change direction it still happens for some reason. also, playing manually does not work for some reason
no like only play the animation manualy if its not already playing , but for move() always call it . give me code snippet so i can know why animation not working manualy
local rotation
local movement
local target
function events.mimic(plr: BasePart)
if plr then
target = plr
if not rotation and not movement then
local plrhum = plr.Parent:FindFirstChildOfClass("Humanoid")
rotation = runservice.Heartbeat:Connect(function()
alignor.CFrame = CFrame.lookAt(root.Position, Vector3.new(target.Position.X,root.Position.Y,target.Position.Z))
end)
if plrhum then
movement = plrhum.Changed:Connect(function(prop)
if prop == "MoveDirection" then
if not a_run.IsPlaying then a_run:Play() end
hum:Move(-plrhum:GetMoveVelocity())
elseif prop == "Jump" then
local s = hum:GetState()
if s ~= Enum.HumanoidStateType.Freefall and s ~= Enum.HumanoidStateType.Jumping then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
end)
end
else
movement:Disconnect()
rotation:Disconnect()
end
end
end
-- NPC
local chr = script.Parent.Parent
local hum = chr:FindFirstChildOfClass("Humanoid")
local animator = hum:FindFirstChildOfClass("Animator")
-- Animations
local animations = chr.Animations
local humanims = chr.Animate
local a_spawn = animator:LoadAnimation(animations.spawn)
local a_dual = animator:LoadAnimation(animations.dual)
local a_quickshot = animator:LoadAnimation(animations.quick)
local a_run = animator:LoadAnimation(animations.run)
...
movement = plrhum.Changed:Connect(function(prop)
if prop == "MoveDirection" then
if a_run.IsPlaying == false then print(1) a_run:Play() end
hum:Move(-plrhum:GetMoveVelocity())
...
end
else
a_run:Stop()
movement:Disconnect()
rotation:Disconnect()
end
end
end
if this doesnt work maybe the problem in the animation itself