Here’s a solution that should be somewhat more accurate (but more complex) than the ones above, given that humanoid states can be volatile
local rootPart = enemyPlayer.HumanoidRootPart
local rootPartHeight = enemyPlayer.Humanoid.HipHeight + rootPart.Size.Y / 2; -- calculate height of the root part from the bottom of the character
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = { enemyPlayer }
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
repeat
local raycast = workspace:Raycast(rootPart.Position, Vector3.new(0, -9000, 0), rayParams)
local distance;
if raycast then
distance = (rootPart.Position - raycast.Position).Magnitude
end
wait()
until distance and distance <= rootPartHeight
this casts a ray downwards from the HumanoidRootParts position and checks to how far away we are from the closest ground. if our distance is that of our rootpart-height then the repeat loop exits
If you haven’t yet looked into learning raycasting yet I urge you to try it as soon as you can