Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(ANSWERED)I tried to use ray cast, and it gave me an error, why?

Asked by 4 years ago
Edited 4 years ago

I was testing out ray cast, and I made this script:

while wait(1) do
local ray = Ray.new(script.Parent.Position, Vector3.new(0,500,0))
local hit = game.Workspace:FindPartOnRayWithIgnoreList(ray, script.Parent) --HERE
print(hit)
end

and it gave me the error: Unable to cast value to Objects Someone please tell me how I can fix it. Any form of help is appreciated :-)

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

The second argument to :FindPartOnRayWithIgnoreList needs to be an array of objects. If you only want to have script.Parent, then you could rewrite it as

local hit = game.Workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
0
Thanks! marioman1932 48 — 4y
Ad

Answer this question