Rays are not at the position i want them to be at

so i have made 3 rays
first ray is supposed to hit the middle the middle (a part in the middle of the base) from the x direction, second ray - from the y direction and the third ray - from the z direction.

Here is a picture in case you didnt understand me


But instead what i get is this: (the neon part is Middle)

heres the script:

local rayparams2 = RaycastParams.new()
local ray1 = Ray.new(plot.Middle.Position+Vector3.new(largestsize,0,0),plot.Middle.Position)
local ray2 = Ray.new(plot.Middle.Position+Vector3.new(0,largestsize,0),plot.Middle.Position)
local ray3 = Ray.new(plot.Middle.Position+Vector3.new(0,0,largestsize),plot.Middle.Position)
local res1 = workspace:Raycast(ray1.Origin,ray1.Direction,rayparams2)
local res2 = workspace:Raycast(ray2.Origin,ray2.Direction,rayparams2)
local res3 = workspace:Raycast(ray3.Origin,ray3.Direction,rayparams2)

Second argument is not the position you want it to look at, it’s the direction.
And you don’t have to use Ray.new() with workspace:Raycast()

local rayparams2 = RaycastParams.new()
local pos1 = plot.Middle.Position+Vector3.new(largestsize,0,0)
local pos2 = plot.Middle.Position+Vector3.new(0,largestsize,0)
local pos3 = plot.Middle.Position+Vector3.new(0,0,largestsize)
local res1 = workspace:Raycast(pos1, pos1 - plot.Middle.Position, rayparams2)
local res2 = workspace:Raycast(pos2, pos2 - plot.Middle.Position, rayparams2)
local res3 = workspace:Raycast(pos3, pos3 - plot.Middle.Position, rayparams2)

oh, let me try that, didnt know it works like this. i thought its like cframe where you give the position you want it to look at

1 Like

i have changed the script to yours, but now i am getting this error:
image
That means the ray returns nil
heres the script, perhaps i have done something wrong

local rayparams2 = RaycastParams.new()
			local pos1 = plot.Middle.Position+Vector3.new(largestsize,0,0)
			local pos2 = plot.Middle.Position+Vector3.new(0,largestsize,0)
			local pos3 = plot.Middle.Position+Vector3.new(0,0,largestsize)
			local ray1 = Ray.new(pos1, pos1 - plot.Middle.Position)
			local ray2 = Ray.new(pos2, pos2 - plot.Middle.Position)
			local ray3 = Ray.new(pos3, pos3 - plot.Middle.Position)
			local res1 = workspace:Raycast(ray1.Origin,ray1.Direction, rayparams2)
			local res2 = workspace:Raycast(ray2.Origin,ray2.Direction, rayparams2)
			local res3 = workspace:Raycast(ray3.Origin,ray3.Direction, rayparams2)

Please don’t use rays, just use the script the same way I sent it.

ill try that, if thats why its not working.

image
looks like thats not the issue

Which line is giving you the error

snapToGrid(pos,plot.Middle.CFrame,itemTransparent,results.Position.X,results.Position.Z,results.Normal,results.Instance,res1.Normal,res2.Normal,res3.Normal)

snap to grid is a function im using to snap the hitbox to grid

You could check if the result is nil or not first

i did print(res1,res2,res3)
image

Try this one instead

local rayparams2 = RaycastParams.new()
local pos1 = plot.Middle.Position+Vector3.new(largestsize,0,0)
local pos2 = plot.Middle.Position+Vector3.new(0,largestsize,0)
local pos3 = plot.Middle.Position+Vector3.new(0,0,largestsize)
local res1 = workspace:Raycast(pos1, plot.Middle.Position - pos1, rayparams2)
local res2 = workspace:Raycast(pos2, plot.Middle.Position - pos2, rayparams2)
local res3 = workspace:Raycast(pos3, plot.Middle.Position - pos3, rayparams2)
1 Like

image