How to see if player is standing on part?

I want a boolean to see if a player is standing on a part. What would that be? Like is there a function that returns a bool or something?

1 Like

use a parts .touched event and add it to a table for debounce and when the .touchEnded event fires remove said player from table

2 Likes

Doesn’t seem to be working, as I’m standing on the NPC’s head and it’s saying it’s false:

image

image

1 Like

I’d just fire a raycast downwards. You can also use the touched events like Decablocks was saying, though I don’t think those aren’t super reliable.

It might be a problem with your code.

5 Likes

Simply either use .Touched events, or use part:GetTouchingParts() and see if it is a descendant of a player.

https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts

2 Likes

BasePart:GetTouchingParts has been superseded by Workspace:GetPartsInPart

1 Like

https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts

Not yet, you’re likely thinking of Region3 functions.

2 Likes

“Additionally, WorldRoot:GetPartsInPart can be used in place of Part:GetTouchingParts, and is a better choice most of the time.”

I did not say that BasePart:GetTouchingParts is deprecated. As this post states, there “are a few niche cases” that is preventing the follow through.

No explicit mention of it being superseded either, I’ll wait for the official documentation to state as such.

Nope, I’m very sure it isn’t.

What’s the difference between them? Is one more accurate/reliable?

One will fire a signal whenever the touch begins. This is useful for detecting everytime there is a touch at the moment it happens.

The second one checks if they are touching or not, and does not fire any signal as soon as it happens.

1 Like

Using Touched and TouchEnded works, just not super reliability. The code can be written to account for the majority of this though, so because your code doesn’t work I assume that the code doesn’t do that and therefore has a problem.

For the use case you gave you should use GetTouchingParts over Touch and TouchEnded anyways.

The Touched event fires when a part touches the given part. GetTouchingParts gets the parts currently touching a given part.

The biggest problem with checking if a player is standing on another part with these methods is that the legs don’t always touch the ground when they should. The best way to do this would be to have a hitbox part or use raycasting.

If you just need to get if the character is touching another part, you should use GetTouchingParts either on the non-character part or on both the feet.

If you need to get when the character touches a part, use Touched.

If you need very precise error free checking, use raycasting. Note that unless you use multiple raycasts the raycast will only check directly downwards.

Another solution for basically error free checking is a hitbox part (below the feet positioned relative to the root part) and using GetTouchingParts. This solves a lot of the problems with other solutions. Note if you weld it to the character to make it massless and non-collide.

1 Like