Using raycast to check if part is on ground doesn't seem to work

I am trying to figure out how I can check if the part is on the ground and not on a wall or ceiling by using Raycast that aims towards the ground. The problem is, Raycasts are not good with orientation and it’s confusing to find a way to find the right angle.

Basically, what I am trying to do is make a teleport script where the player can only teleport if their mouse is pointed on the ground and not on the wall or the ceiling and I use a Raycast to check the distance between a part positioned at the mouse’s 3D position and the ground below and check if the distance is around 1 stud so that way, it confirms that the position is on the ground. Can anyone help me resolve this?

elseif workspace:Raycast(hollowpart.Position,,-100,0)) ~= nil then
			if workspace:Raycast(hollowpart.Position,,-100,0)).Distance < 1 then
				hollowpart.BrickColor ="Bright green")
				highlight.FillColor =,1,0)
				highlight.OutlineColor =,1,0)
				billboard.ImageLabel.ImageColor3 =,1,0)
				print("nuh uhhh")
				hollowpart.BrickColor ="Bright red")
				highlight.FillColor =,0,0)
				highlight.OutlineColor =,0,0)
				billboard.ImageLabel.ImageColor3 =,0,0)

um I think you can just do
And just either remove distance or set it to 1

workspace:Raycast(hollowpart.Position,,-1,0)) * Distance)

Doesn’t seem to do anything.

Does the script print out "nuh uhhh " then

Nope, it doesn’t detect any part’s touched underneath which means the raycast returns nil. I tried increasing the height of the part’s position but that didn’t work.

Is the hollow part position correct because I thought you can just do


Yep, it is. Position is fine and all.
(Red means it can’t teleport.)

Try moving the part up by 1 stud as it might be that the ray is going through the part somehow. In which case you would need to lower the distance

I already did that which I mentioned above.

Try printing out the raycasts origin and direction or just doing the math for it then seeing if the position it actually inside the part

This won’t work, the raycast is returning nil so I can’t do anything.

Ok so then just do to see where the ray ended up

local Debugger ="Part")

Debugger.Parent = game.Workspace
Debugger.Name = "Debugger"
Debugger.Size =,1,1)
Debugger.Color3 = Color3.fromRGB(255,0,0)
Debugger.Position = hollowpart.Position +,-1,0)

Found a workaround where I simply had to increase the hollowpart’s position when it’s placed at the mouse’s position.

(The height I tried increasing before was the position inside the Raycast and not the part itself.)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.