How to check if a part is moving

Currently, I want to check if a part is moving cause I have made a train game and I want to check if the train is not moving, when its suppose to be (It got jammed or something). I have tried checking the trains previous position and its current position after 1 second and if the previous position and current difference is lesser than 20, it means its stuck. However, the trains position turns negative after reaching pass a certain point so That will no longer work.

1 Like

You should try Checking the Velocity of your Train

Perferably AssemblyLinearVelocity

5 Likes

Do you know how to assign AssemblyLinearVelocity to a variable. I tried doing

	local Xvalue = game.Workspace.Train:FindFirstChild("TrainCarraige1"):FindFirstChild("Engine").AssemblyLinearVelocity

Aint working

1 Like

Nevermind, I figured out how to do it myself. Thanks for the troubles tho. Really appreciate the help

1 Like

Why are you using FindFirstChild here?

local Xvalue = game.Workspace.Train:FindFirstChild("TrainCarraige1"):FindFirstChild("Engine").AssemblyLinearVelocity

FindFirstChild should only be used for conditions. Unless your using the recursive argument, there is no need for FindFirstChild if your just going to index it without checking if it exists.

That script would function the same as this:

local Xvalue = workspace.Train.TrainCarraige1.Engine.AssemblyLinearVelocity.X
1 Like

I believe he already figured it out according to his post

2 Likes

Yes, I saw that. But I wanted to tell him that he doesn’t need to use FindFirstChild there.

4 Likes

Thanks for the reply/comment. I will not be using FindFirstChild.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.