How to make my targeting part stay at a certain distance from player when mouse is pointing out of range?

Greetings,

I am trying to make a casting indicator, so that when a player goes to cast a long range spell pressing the keybind spawns a part that indicates the current target of the spell and the projected area of effect,
however I can’t seem to get it to work. I am setting it’s cframe to the point where the ray hit something + the normal

here is how it looks
https://streamable.com/mm9cil

local instance, HitPoint, Normal = RayCast(Origin, Direction, MaxDistance, IgnoreList) – Will goto max distance unless something is hit,

  	Area:SetPrimaryPartCFrame(CFrame.new(HitPoint, HitPoint + Normal))
  	if (Area.PrimaryPart.CFrame.p - Root.CFrame.p).Magnitude > 45 then
  		print "max range"
  		Area:SetPrimaryPartCFrame(CFrame.new(Root.Position + HitPoint.Unit * MaxDistance, (Root.Position + HitPoint.Unit * MaxDistance) + Normal))
  	end

However when it goes out of range instead of stying 45 studs(Max Distance) from the player it just disappears instead. If someone could point out the error i am making i’d be most grateful

Thank you for your time

1 Like

I think the problem is that you are pointing it to the sky, a nil value. To fix this I would normalize its vector to a max range. To add on instead of setting its parts cframe with that function you should instead simply set its position to its inverse hit from the players head for example.

Could you please give me an example how to apply that?