How to check if the player's character is stuck inside a part?

so the issue is that sometimes a player may gets stuck inside a part like for example when a player in my game spawns a house and an another player is standing in the plot the house will spawn on top of the player on the plot which then will make him stuck inside the house model so how can i detect if the player is stuck?

btw this is just a small example so what a solution that will work withall circumstances?

and if the script detects that a player is stuck the script will just make him unstuck somehow, idk i think maybe telelport him out of the part but if so then maybe the player teleports to a place where it would make them stuck or teleport them in the air

any help will be appreciated

You can try to experiment with HumanoidStateType and see which state the Humanoid is at when it is stuck in a part by using the Humanoid:GetState() method in a LocalScript.

From there, you can connect the Humanoid.StateChanged event to check the state of the Humanoid, and if it has been in a certain state for some time, send a RemoteEvent to the server to teleport Players out of the part.

This is one way you can do it, there’s many other possible ways.

You can try this code that utilizes spatial queries:

local parts = workspace:GetPartBoundsInBox( -- Returns an array of parts that are inside the character
  Character:GetPivot(), -- Get the characters CFrame
  Character:GetBoundingBox(), -- Get the characters size
  OverlapParams? -- Optional OverlapParams
)

However, this is often not 100% accurate and maybe a bit resource intensive.