Unable to cast Dictionary to RayCastParams [ERROR]

I’m making a throwing knife and i don’t use RayCasting very much. I’m trying to make a ray that ignores the character, etc. Here’s the script:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

tool.Activated:Connect(function()
local throwpos = mouse.Hit.p
local RightHand = plr.Character.RightHand

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {RightHand.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayresult = workspace:Raycast(RightHand, throwpos, RaycastParams)

print(rayresult)

end)

I’ve taken some examples from google, and my script seems to match. But somehow i still get this error:
Capture

I’d really appreciate it if someone could help me out!

RightHand.Position is missing. In your case it uses Instance and not Vector3 as origin.

Thanks, it solved the error, but i don’t get the raycastresult? How would i get that?

1 Like

I think you made a typo: it should be

local rayresult = workspace:Raycast(RightHand, throwpos, raycastParams)

with lowercase r

1 Like

Oh no! That worked, thanks. But somehow i get nil as result??

What’s the error now? Show us your output.

That can mean that the ray didn’t hit anything

Ok, but i’m pointing at the baseplate?

Edit: Nevermind, the baseplate is locked. I think thats the problem.

Try print(rayresult.Position) rayresult contains multiple values you can read off.

That shouldn’t be a problem. I think I know what the problem is. You should try this:

local rayresult = workspace:Raycast(RightHand.Position, throwpos - RightHand.Position, raycastParams)

Yeah good idea, you can also use the UnitRay of the mouse.

Try this:

local rayresult = workspace:Raycast(RightHand.Position, (RightHand.Position - throwpos).Unit * 300, raycastParams)

I think that would be the best yeah! Thanks for helping!

Can i pass the direction and origin trough a RemoteEvent by doing this:

rayresult.Direction, RightHand.Position

(RemoteEvent Parameters)

Edit: Nevermind, i can’t didnt define it.

Yeah, you should be able to.(charz)