Why my ray is glitching?

My problem (Gyazo GIF)

Why is that happening, that makes 0 sense in my head. Ill send here the part of my code that handles that Ray

-- Ray Casting
   	local Ray = Ray.new(Spear.Position, Mouse.Hit.p)
   	Magic.SeeRay(Ray)
   	local Hit, Positionn = game.Workspace:FindPartOnRay(Ray, Character)
   	-- Tweening it to the final position
   	local Tween = TweenService:Create(Spear, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = Positionn})

The ray is not going to the mouse.hit Position. :woozy_face:

Mouse.Hit.p is just where the mouse at, I suggest replacing

with

local Ray = Ray.new(Spear.Position, Mouse.Hit.lookVector * 2500 – 2500 can be any number, its just how far the ray will hit, atleast for workspace:Raycast()

lookVector or LookVector works by what direction the CFrame is looking at
Remember that Mouse.Hit is a CFrame

1 Like

I changed, it’s working fine now, but there’s something wrong, i know your code is correct but you know any way to fix that?

GIF1

GIF2

workspace:FindPartOnRay() is deprecated I believe, use WorldRoot:Raycast()

1 Like

Thanks for you and @HugeCoolboy2007 i didnt know that FindPartOnRay() were Deprecated. now it’s working, what i changed is:

local raycastresult = game.workspace:Raycast(Spear.Position, Spear.CFrame.lookVector*2500)
		if raycastresult then
			-- Tweening it to the final position
			local Tween = TweenService:Create(Spear, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Position = raycastresult.Position})
			-- Creating a Ring
			Magic.NewRing("Hie", Spear, 0.3, 30)
			-- Shaking the camera
			camShake:Shake(CameraShaker.Presets.Explosion)
			Tween:Play()
		else
			return
		end

That solved the problem. GIF of how it’s working now:
GIF