I want support as to figuring out why my NPC is acting like this and how to fix it
My NPC’s HumanoidStateType is defaulting to running when it should be idle, even though the running state is disabled for bug testing
I’ve tried disabling the running state as stated before, I’ve also looked for a bit on the dev forum but couldn’t find anything relating to my issue
local tool = script.Parent
local idle = Instance.new("Animation")
idle.AnimationId = "rbxassetid://73752435833124"
local walk = Instance.new("Animation")
walk.AnimationId = "rbxassetid://73867328843296"
local Humanoid = tool.Parent.Humanoid
track = tool.Parent.Humanoid:LoadAnimation(idle)
track.Priority = Enum.AnimationPriority.Idle
track.Looped = true
track:Play()
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false) --IMPORTANT
tool.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.None)
tool.Parent.Humanoid.StateChanged:Connect(function()
track:Stop()
print(tool.Parent.Humanoid:GetState())
if tool.Parent.Humanoid:GetState() == Enum.HumanoidStateType.Running then
track = tool.Parent.Humanoid:LoadAnimation(walk)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
else
track = tool.Parent.Humanoid:LoadAnimation(idle)
track.Priority = Enum.AnimationPriority.Idle
track.Looped = true
track:Play()
end
end)
while wait() do
print(tool.Parent.Humanoid:GetState())
if Humanoid then
if Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
print("the state should be running right now")
else
Humanoid:ChangeState(Enum.HumanoidStateType.None)
print("the state SHOULD be idle right now")
end
end
end
while wait() do
if tool.Parent.Humanoid:GetState() == Enum.HumanoidStateType.None then
print("idle")
end
print(tool.Parent.Humanoid:GetState())
end
Note that the tool isn’t actually a tool but just a model with a disabled motor6d in it
Followup:
I simplified and tweaked the code a lot, and it works when used on a player, but doesnt work for the npc I made. The issue is that I’m using :MoveTo() while the code requires MoveDirection
local humanoid = script.Parent.Humanoid
local idle = Instance.new("Animation")
idle.AnimationId = "rbxassetid://73752435833124"
local run = Instance.new("Animation")
run.AnimationId = "rbxassetid://73867328843296"
local jump = Instance.new("Animation")
jump.AnimationId = "rbxassetid://82188168559304"
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if track then
track:Stop()
end
if humanoid:GetState() ~= jump then
if humanoid.MoveDirection == Vector3.new(0, 0, 0) then
track = humanoid:LoadAnimation(idle)
track.Looped = true
track.Priority = Enum.AnimationPriority.Idle
track:Play()
else
track = humanoid:LoadAnimation(run)
track.Looped = true
track.Priority = Enum.AnimationPriority.Movement
track:Play()
end
end
end)
humanoid.Jumping:Connect(function()
if track then
track:Stop()
end
track = humanoid:LoadAnimation(jump)
track.Looped = false
track.Priority = Enum.AnimationPriority.Action
track:Play()
track:AdjustSpeed(0.5)
end)
Lol ya It works because you’re using ~= as your comparison operator. The return of GetState() is an Enum.HumanoidStateType and your effectively making sure sure its not an Animation object – which it never would be. You’re comparing apples to oranges – the system breaks breaks if you ever need to make an == comparison. So, I trust you … dont understand what it is you’re doing
On the topic of your actual problem:
You could substitute MoveDirection for AssemblyLinearVelocity which will similarly detect movement, and couple it with a check to make sure WalkToPoint isn’t nil. Adding that check will make sure it only animates when its using MoveTo()