Mouse.Hit Range

I want to make a part follow the player but only within 30 studs. The problem is that it is snappy.

this is the code I’m using

	if mouse.Hit then
		RootPos = c.HumanoidRootPart.Position
		if (RootPos - mouse.Hit.Position).Magnitude < 30 then
			workspace.MeshPart.Position =,0,mouse.Hit.p.Z)

Try clamping the meshpart’s position to a radius of 30 instead instead of checking the mouse.hit magnitude.

You can achieve this by calculating the difference between your position and the mouse’s, then clamping each axis between -30 and 30

You can of course go more advanced but hopefully this puts you on the right track.

i tried the clamp thing before and i was wondering why it only went to the right. Its because i forgot about the negitives :man_facepalming:

1 Like

Haha it’s alright, it happens! Happy developing!