How do you check if an npc is moving or not?

will look something like this

local NPCOLDPOSITION
	while true do 
	if (NPC.BODYPART.Position - NPCOLDPOSITION).Magnitude > 1 then
		print("They have moved more than a stud :O")
	end
	NPCOLDPOSITION = NPC.BODYPART.Position
	wait(1)
end

That works in that sense, but I don’t think that’s what they want. Also, someone could move then move back, and it would not detect it.

if you reduce the wait this is less likely and if movements are that miniscule does it matter? questions questions context context

can you be more specific on whats going on in your game why u need to know if an NPC is moving or has just moved @Wyzloc

@Wyzloc I tested out the code I sent you (the second one). The results:
https://gyazo.com/1ba9ae938c9d4a4d260c5bddf59532f2

Have you tested it on an Npc yet? I’d try testing it multiple times because for me it did work, but sometimes the Npcs would be running in place.

@S0MBRX I was specific all I’m asking is how to check if an Npc is moving or not so I can make them play running animation when they are and idle animation when they arent on the Client.

Do the NPCs have HumanoidRootParts?

Indeed they do they’re just R15 Rigs after all.

make sense yeah vinnys way works but also why dont you just run the animations when you make the NPC’s move in the first place?

Allow me a moment to test it out.

I think I know why it runs sometimes. My theory is that the velocity from the idle animation is causing the HumanoidRootPart to move a bit.

That might be the issue. I used HumanoidRootPart in attempts to avoid that issue. Here are my results testing on the dummy.
https://gyazo.com/05223f9709e6d0affc6cd60a27a8788f

Ah actually, I take that back, I noticed something. When the game first loads, it continuously sees the HumanoidRootPart as MOVING. I am investigating right now.

@S0MBRX That’s what I’ve been doing, but it causes bugs because when the player stops moving and starts moving it will cause overriding animations sometimes. Both idle and running are looped animations, the animation won’t always play the correct animation for the last action (walking, standing).

@Volieb Yeah that’s what the problem is for me, I’m not entirely sure why this is the case but I could simply just make the Npcs jump when theyre first spawned.

@Wyzloc I figured it out.

When the HumanoidRootPart is slightly rotated, the velocity is above 0, but extremely small (like, 0.00004 small). To solve this, I made the following adjustments:

if math.floor(humanoidRootPart.Velocity.Magnitude)>0 then
    -- is moving
else
    -- not moving
end
3 Likes

This means the velocity must be at least 1. 0.5 will not trigger this, unless I adjusted it a bit more.

Yeah that solved the issue, I can’t believe it took that long to fix something so simple Roblox is weird.

Glad you were able to figure it out. Good luck and goodnight :grin:

1 Like

oh yes i have had these issues in the past managing user input with animations and scripts can be hard but you can use logic to make sure animations/scripts dont run simultaneously sorry for the late reply its really late here and im gonna sleep but yeah glad u got a solution goodnight

Sorry about that, the humanoid doesn’t have an AssemblyLinearVelocity property, I was thinking of their root.

1 Like