How to get mouse.hit if its far away?

Hello

So i want to get how far away mouse.Hit, if its far away then it dont do anything

I’m not sure, but does this needs magnitude ?

Hello A_DragonWithClaws!

Yes, you have to use magnitude to get the distance between your character and the hit position, your script should be something like this:

local MaxDistance = 100
local HitPosition = mouse.Hit.p

local DistanceInStuds = (HitPosition - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude

if DistanceInStuds < 100 then
   -- Run your code
else
   print("Too far away")
end

Hope this helps!

Thankssss so much this helped me alot understanding magnitude