im using a non-human npc so the default roblox animate script wont work properly
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
local anim = script.Animation
local humanoid = script.Parent.Humanoid
local aniload = humanoid:LoadAnimation(anim)
local isRunning = false
humanoid.Running:Connect(function(spd)
if spd > 0 and not isRunning then
print("running")
aniload:Play()
isRunning = true
elseif spd == 0 and isRunning then
print("stopped")
aniload:Stop()
isRunning = false
end
end)
The issue is you are using running instead of Humanoid:GetState()
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
local anim = script.Animation
local humanoid = script.Parent.Humanoid
local aniload = humanoid:LoadAnimation(anim)
Humanoid.StateChanged():connect(function()
local state = Humanoid:GetState()
if state == Enum.HumanoidStateType.Running then
print("running")
aniload:play()
elseif state == Enum.HumanoidStateType.PlatformStanding or state ~= Enum.HumanoidStateType.Running then
print("not running")
aniload:stop()
end
end)
Humanoid.Running wont fire the event trigger if speed gets down to 0 because it isn’t technically “running” anymore.
Try setting the elseif spd == 0 to elsif spd < 2
also, where you declare if speed == 0 and isRunning == false, it will never pass the parameter check because isRunning is only set back to false once it reaches past the parameter