Walking/running animation not playing when mimicking player movement

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
1 Like

the code snippet u sent doest show where do u play the animations in your code, maybe add an runanimation:Play() here?

1 Like

it plays via the default ROBLOX animate script

2 Likes

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

make an IsMoving variable so it dont get called repeatedly . and why doesnt playing the animation manualy work?

that’s what I would like to know haha

it does eventually need to be called every time the player changes their direction though, otherwise the npc can’t mimic the player accurately!

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

do u get any errors? show me the a_run variable

0 errors, and it does indeed go through

-- 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

1 Like

the problem happened to be inside the actual roblox animate script ^^

the walk animation and run animation seemed to try to play over each other for some reason? removing the walk animation seemed to do the trick!

I’ll mark you as the answer though as you were a good help! : p

2 Likes

thanks! have a great time scripting.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.