Freezing entity physics when still

Hey FP lua daycare. I have an entity that is thrown (like the TTT Health Station) from a SWEP and I would like the entity to be frozen when it comes to it’s first ‘still’ (not moving) state. How would I go about this? This was my last attempt in the entity’s lua



function ENT:StopMove()
	local phys = self:GetPhysicsObject()
	local moving = self:GetVelocity()
	 
		if ( moving == 0 ) then
			if phys and phys:IsValid() then
				phys:EnableMotion(false)
			end
		end
end

You would place it in a think hook.

Makes sense! Tried changing the hook to ENT:Think() though but it didn’t seem to do the trick. Is my function written wrong?

Try putting prints in (it will be a pain cause it will print every think, but it will help narrow down which statements are getting called)

Instead of comparing the velocity, you’re better off just checking to see if it’s sleeping with

PhysObj:IsAsleep.

GetVelocity returns a vector, not a number. Either use :Length() or check if it’s Vector( 0, 0, 0 ). The way you currently have it, it would look like Vector( 0, 0, 0 ) == 0 which would be false.