I have a system that spawns an NPC at a specified parts position, and then uses humanoid:MoveTo(anotherPart.Position) to make the humanoid walk to a specific position. I am attempting to animate the humanoid inbetween the start point and end point positions using humanoid.StateChanged to create a simple walking animation. The StateChanged event works fine when the humanoid begins traveling towards the target position, but when the humanoiud reaches the target position and WalkToFinished is fired, the humanoid state does not change, so the animation script never knows when to stop the animation, because the HumanoidStateType never changes. Is there any reason WalkToFinished does not change the HumanoidStateType? I would assume that once the NPC is no longer attempting to walk, the state should change to idle, and trigger the StateChanged event.
As far as I know, Humanoid.MoveToFinished or any single event doesn’t change anything except for getting signals. So, there’s no reason for Humanoid.MoveToFinished to change the HumanoidStateType. It may be that your Humanoid.StateChanged might be disconnected after a certain condition or so. Can you show the script?
humanoid.StateChanged:Connect(function(currentState, newState)
if newState == Enum.HumanoidStateType.Running then
-- play animation
else
-- stop animation
end
end)
Search for “Animate script” in toolbox and whether it’s r15 or r6
Then put the script in the npc
I’ll check it out. I just can’t stand using other people’s scripts… I have to make my own based off of that one haha
The animate script is actually made by roblox so yea
Just for anybody who finds this post in the future who’s maybe experiencing a similar problem, the problem was actually that the “Running” enum is still applied to a humanoid even when they are not moving. So when a humanoid reaches it’s MoveTo position, the running state is still applied, which means there is no StateChanged event fired if you are attempting to animate an NPC from a separate script using the StateChanged event. This problem was easily fixed by applying the following code into the script that actually moves the humanoid, using humanoid:ChangeState() after MoveToReached.
humanoid:MoveTo(somePart.Position)
humanoid.MoveToReached:Connect(function()
humanoid:ChangeState(Enum.HumanoidStateType.None) -- since there is no "Idle" enum, I chose "None".
end)