part.Velocity.Magnitude Not Recognized Correctly

I’ve been working on a system that routinely anchors any part that has a Velocity.Magnitude of 15 or less, to reduce lag. However, it just doesn’t seem to recognize when a part’s magnitude is less than 15. By reversing the if statement, I know that the function does run and that the code executes correctly, it’s just that something is wrong when it comes to firing it normally. Any help is appreciated!

local function hasProp(object, prop)
	local property = object[prop]
end

while true do
	for i, v in pairs(workspace:WaitForChild("currentMap"):GetDescendants()) do
		local success1 = pcall(function() hasProp(v, "Anchored") end)
		local success2 = pcall(function() hasProp(v, "Velocity") end)
		if success1 and success2 and v.Velocity.Magnitude <= 15 then
			print(v.Velocity.Magnitude .. ", " .. v.Name)
			v.Anchored = true
			v.AssemblyLinearVelocity = Vector3.new(0,0,0)
			v.AssemblyAngularVelocity = Vector3.new(0,0,0)
		end
		task.wait(2)
	end
end
1 Like