How to make magnitude match a cylinder?

I’m trying to make a range system for a tower defense game and the magnitude doesn’t match with the size of the cylinder. The size of the cylinder is 30 studs (I am aware that is the diameter, but the distance from the tower to the edge of the cylinder should still be 15 studs) and the magnitude printed between the humrootpart of the tower and enemy is 9.9~.

I know the difference will be minute, but it will annoy me if it is not matching properly.

I am making this to see if I am missing something or if there is a better way to find the distance between them. Or just to see how magnitude works.

1 Like

I’m a bit confused.

Is it the wrong size? Is it in the wrong spot? Could you clarify?

1 Like

I’m just a bit confused about how magnitude works. The cylinder is 30 studs wide (15 radius) but it says the magnitude between the enemy and tower is 9 (studs?) away from the tower.

1 Like

Could you show the code for the cylinder?

Below is the code to stop the enemy when the magnitude is under or equal to 10.

if v.HumanoidRootPart.Position.Magnitude - script.Parent.HumanoidRootPart.Position.Magnitude <= script.Parent.RangeValue.Value then
			print(v.HumanoidRootPart.Position.Magnitude - script.Parent.HumanoidRootPart.Position.Magnitude)
			v.HumanoidRootPart.Anchored = true

I don’t know if I have found the distance wrong?
If there is a more alternate way to find distance I’m open to learn that.
Also the cylinder is just an indicator for how big the range for the tower should be.

1 Like

It should be

if (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude <= script.Parent.RangeValue.Value then