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

How to get the part that a ray hits?

local handle = script.Parent.Handle

script.Parent.Activated:Connect(function()
	local plr = game.Players.LocalPlayer
	local mouse = plr:GetMouse()
	local target = mouse.Target
	if target.Name == "Well Water" then
		local fishray = Ray.new(handle.Position,(handle.CFrame.p - mouse.Hit.p).unit * 100)
		local part, position = workspace:FindPartOnRay(fishray, plr.Character)
		if part and part.Name == ("Well Water") then
			print "success"
		end
	end
end)

1 answer

✓ Accepted answer

That most likely means a part isn't being found.

For your if command, do

if part and part.Parent and Part.Name == "Well Water" then
	--code
end

2 comments

0

So how do I find the part? I'll post the basic script.

0

You find it by using FindPartOnRay. A ray won't always find a part, if you fire it towards the sky, it will return nil.

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