so i’m trying to make my npc stop it’s run animation when he isn’t moving and make the animation play if he is moving. however, the problem is that it won’t stop the animation at all and it’ll just keep playing.
i tried searching up on the forum but i couldn’t get it to work from the posts that i read. ty for ur help!!!
somedudethatfollowsuHumanoid.Running:Connect(function(speed)
local animFolder = somedudethatfollowsu.Animations
local randomNumber = math.random(1,2)
local runAnim = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animFolder.run)
if speed > 0 or somedudethatfollowsuHumanoid.MoveDirection.Magnitude > 0 then
if not runAnim.IsPlaying then
runAnim:Play()
end
if randomNumber == 1 then
if not canJumpDB then
canJumpDB = true
somedudethatfollowsuHumanoid.Jump = true
canJumpDB = false
end
end
else
if runAnim.IsPlaying then
runAnim:Stop()
end
end
end)
vid:
Using running can be really wonky so switch it to listening for move direction change
somedudethatfollowsuHumanoidGetPropertyChangedSignal(“MoveDirection”):Connect(function()
local animFolder = somedudethatfollowsu.Animations
local randomNumber = math.random(1,2)
local runAnim = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animFolder.run)
if somedudethatfollowsuHumanoid.MoveDirection.Magnitude > 0 then
if not runAnim.IsPlaying then
runAnim:Play()
end
if randomNumber == 1 then
if not canJumpDB then
canJumpDB = true
somedudethatfollowsuHumanoid.Jump = true
canJumpDB = false
end
end
else
if runAnim.IsPlaying then
runAnim:Stop()
end
end
end)
1 Like
hey Dr,
thanks so much for your help once again man!!!
unfortunately the animation won’t play now so i can’t really test it to see if it stopped. perhaps there’s something in the rest of my script that is preventing the animation from playing?
local somedudethatfollowsu:Model = workspace.somedudethatfollowsu
local somedudethatfollowsuHumanoid:Humanoid = somedudethatfollowsu.Humanoid
local pfs = game:GetService("PathfindingService")
local RS = game:GetService("RunService")
local insertService = game:GetService("InsertService")
local startingPosition = somedudethatfollowsu:FindFirstChild("HumanoidRootPart").Position
local endingPosition = workspace.SpawnLocation.Position
local connection = nil
local canJumpDB = false
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
connection = RS.Heartbeat:Connect(function()
local mag = (somedudethatfollowsu.HumanoidRootPart.Position - c.HumanoidRootPart.Position).Magnitude
somedudethatfollowsuHumanoid:MoveTo(c.HumanoidRootPart.Position)
end)
end)
end)
somedudethatfollowsuHumanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
local animFolder = somedudethatfollowsu.Animations
local randomNumber = math.random(1,2)
local runAnim = somedudethatfollowsuHumanoid.Animator:LoadAnimation(animFolder.run)
if somedudethatfollowsuHumanoid.MoveDirection.Magnitude > 0 then
if not runAnim.IsPlaying then
runAnim:Play()
end
if randomNumber == 1 then
if not canJumpDB then
canJumpDB = true
somedudethatfollowsuHumanoid.Jump = true
canJumpDB = false
end
end
else
if runAnim.IsPlaying then
runAnim:Stop()
end
end
end)