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

FindPartOnRay isn't returning anything when I click on a part. What am I doing wrong?

So. I'm trying to make a grappling hook. Here's my code.

It's in a local script.

local p = game.Players.LocalPlayer
repeat wait() until p.Character
local c = p.Character
local m = p:GetMouse()

m.Button1Down:Connect(function()
	--mouse hit position and making a ray so i can make a rope afterwards
	local hit = m.Hit.p
	local ray = Ray.new(c.RightHand.Position - hit.unit * 300)
	
	--self-explanatory
	local part, position = workspace:FindPartOnRay(ray)
	
	--testing where the mouse hit is
	local d = Instance.new("Part", workspace)
	d.Anchored = true
	d.Position = hit
	
	print(part)
end)

Whenever I test this, I click on a block and it returns nothing. The 'd' part locates itself on the block. FindPartOnRay just isn't working for me.

Any help is appreciated, thanks.

EDIT: It is working. When the ray decides to work and actually point where my cursor is pointing. WHY IN ALL OF HELL WOULD IT NOT POINT WHERE MY CURSOR IS?

1 answer

I made an error when creating the Ray. Instead of putting the origin and direction I forgot to include origin.

ray = Ray.new(c.RightHand.Position, (c.RightHand.Position - hit).unit * 300)

1 comment

0

ok

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