Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a raycast face an objects face?

I'm new to raycasting so, i've made a tool and i am trying to create a way starting from the objects face. But i when i do so the the result isnt what i want, i want it so that when the object moves and rotates and stuff, the ray follows it and faces it, but the ray just is still and doesnt change, im trying to check what part is firstly infront of the object basically.

My script:

if script.Parent.Aiming.Value then
			local ray = Ray.new(script.Parent.aimS.CFrame.p, Vector3.new(0, 0, 1))
			
			local partHit = workspace:FindPartOnRay(ray)
			print(partHit)
else

Please help

Thx

2 answers

Hello, I believe I have an answer yo your question:

while true do
wait()
	if script.Parent.Aiming.Value then
            	local ray = Ray.new(script.Parent.aimS.CFrame.p, Vector3.new(0, 0, 1))

           	 local partHit = workspace:FindPartOnRay(ray)
           	 print(partHit)
	else
		--Your Script
	end
end

I basically added a while true do loop, which will keep creating the Ray.

I managed to fixed the script with the help of the discord server, thanks tho.

This discussion is preserved as it was. New answers, comments, and votes are closed.