How can i check if a part is directly above another part

I’m not sure how to go about this, all I want to do is check if a part is above the HumanoidRootPart.

raycast downwards to see if somethings below something

wouldn’t this only work on the Y axis, because i want it to work on any axis.

Raycasting is the way to go. Make sure to ignore the Humanoids parts so they don’t trigger a collision.

I’m not quite sure if I understand what you mean, but you can raycast in any direction. Assuming you meant above, relative to the part, that is also possible.

I don’t understand, how would you tell if the part is above just from a ray. As i was saying i want it so no matter where the part is, it’ll check if it’s above the HumanoidRootPart or not.

When you cast a ray you receive a result, containing what and where it hit. If you cast a ray directly upwards and there is (for example) a roof, then your raycast would return the roof Part. If it doesn’t hit anything it will return nil.

If you have a result, then something is above the HumanoidRootPart, if you don’t have a result there is nothing.

1 Like

I think this will only work if the part is directly above, that’s not what i’m trying to do, i want it so even if the Z and X axis don’t align, it’ll still check if it’s above the HumanoidRootPart or not.

Not quite,


Point A is your HumanoidRootPart, point B is your roof.

The ray (yellow) will go straight up and hit at Point C. It will return that it hit Part B at coordinates C.

I’m not talking about roofs, i’m talking about a small part, might as well be about (3,3,3) large.

I think i cracked it, rather than raycasting, get their both Y axis, and check the difference.

Well, this works the same no matter the size. The roof part might as well be (0.1, 0.1, 0.1). As long as something touches the ray it will return what it found.

I might have misunderstood what you meant. Do you simply mean there is a part with a Y-level above the humanoid, yet nothing of it is right above it?

If you want to check if B is above A (Y-level-wise), then you need to loop through each and every part and compare Y-levels.

Yeah, comparing the Y axis worked.

If it’s for any distance then just check for the difference between their positions and do magnitude

Did you consider raycasting in the direction of the lower part’s UpVector?

We discussed this earlier, I believe his goal was to check if a part was directly above him coordinate wise rather than coverage-wise.

However raycasting upwards would allow him to get the potential part immediately without having to loop through all parts.