How do I detect if a part is not moving in a script?

  1. What do you want to achieve? Keep it simple and clear!

I want to be able to detect if a part is not moving in a script, but this is probably simpler than I thought. I wouldn’t be surprised.

  1. What is the issue? Include screenshots / videos if possible!

The reason why, is because I’m making a free build tycoon and ores are flooding the tycoon when conveyors don’t run (they don’t run because I have a power system in my tycoon). I want to detect if the part is not moving so after about 10 secs of it not moving, I can destroy the ore.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve looked on the developer hub for people asking the same question, but all I found was stuff about how to detect if a player is moving.

2 Likes

Check the magnitude of its velocity and see if it’s 0:

if math.floor(part.Velocity.Magnitude) == 0 then 
    -- code
end

You want to floor it because usually the magnitude will never be exactly 0 (ex 0.00352, 0.526, 0.2556)

12 Likes

You could always wrap your ores up in a table and determine the first element’s magnitude like @rek_kie suggested.

Optionally, use Debris to delete these parts if they still remain for a certain amount of time, like a time out.

2 Likes