So, I started learning about raycasting a few days ago, and I decided to try to make a tool out of it. But, I ran into a slight error:
17:47:47.895 - FindFirstAncestorWhichIsA is not a valid member of Vector3
How would I be able to fix that?
A little snippet of code:
local FrontRay = Ray.new(script.Parent.Position, Vector3.new(0,0,-1))
local LeftRay = Ray.new(script.Parent.Position, Vector3.new(-2,0,0))
local RightRay = Ray.new(script.Parent.Position, Vector3.new(2,0,0))
local TopRay = Ray.new(script.Parent.Position, Vector3.new(0,1,0))
local objectsTouched = {workspace:FindPartOnRay(FrontRay), workspace:FindPartOnRay(LeftRay), workspace:FindPartOnRay(RightRay), workspace:FindPartOnRay(TopRay)}
for i, object in pairs(objectsTouched) do
if not object == FrontRay or LeftRay or RightRay or TopRay then
print(object) -- prints until ray is detected
local objectParent = object:FindFirstAncestorWhichIsA("Model") -- Error here
I tried many things such as ignoring the ray:
workspace:FindPartOnRay(FrontRay, Ray)
I also tried this:
workspace:FindPartOnRay(FrontRay, FronRay)
But it gave me more errors.
I also searched youtube and even looked at the developer hubs raycasting laser tool, but still, I didn’t fix my problem.
I know you can simply create a part and then fire touched events(as of right now I think that), but that would be too messy and would probably use up more time to register(I don’t want that).
How would I go around this?
All help is greatly appreciated.