Answered by
5 years ago Edited 5 years ago
Since Roblox doesn't have anything that would check if there's anything overhead I would recommend casting a ray. Just note that when you raycast, do not overdo it! Raycasting a lot way too fast can hurt your game performance. The simplest and fastest way to do it can be done by following the following:
Create a new ray:
1 | ray = Ray.new(chr.Head.Position, Vector 3. new( 0 , 100 , 0 )) |
This creates a ray that starts at your character's head and finishes 100 studs up into the air.
Then you would want to get anything that the ray collided with:
1 | Object, Position = workspace:FindPartOnRay(ray, chr, false , true ) |
This looks for any collisions in the ray. The first thing you put into it is the ray itself, the second thing is what to ignore (which is the character because that doesn't count as an object overhead), the third is something you can ignore for now (leave it false), and the last one is to ignore water as being something it hits. Object is the part or whatever the ray hit and Position is the position of that object that the ray hit.
Lastly, you check if it hit something (check if it isn't nil).
Note that this ray will not ignore players that jump on your head because we only told it to ignore your own character.
To fix this issue we can look if there is a "Humanoid" within the object we hit.
2 | if ( not Object:FindFirstChild( "Humanoid" )) then |
I recommend learning more about raycasting here and here so you can fix your own issues and so you can understand how it works better. This will help you understand what you are doing.
If you have any questions or issues please contact me. ;)