You can use 2 raycasts, one where the humanoid rootpart is (pointing where the humanoid rootpart is looking) and another at the humanoid rootpart's position but 1.5 studs up (the "heads" position). The one on the humanoid rootpart detects if there's a part and the one on the "head" detects if there is no part. This is a very easy way to detect the top of a part.
1 | local rayDetectPart = Ray.new(char.HumanoidRootPart.Position,char.HumanoidRootPart.CFrame.LookVector* 2 ) |
2 | local hit,point,normal = workspace:FindPartOnRay(rayDetectPart, char) |
4 | local rayNoDetectPart = Ray.new(char.HumanoidRootPart.CFrame+Vector 3. new( 0 , 1.5 , 0 ),char.HumanoidRootPart.CFrame.LookVector* 2 ) |
5 | local nohit,nopoint,nonormal = workspace:FindPartOnRay(rayNoDetectPart, char) |
7 | if hit and not nohit then |
Very lazily made but it takes very little load on a computer's CPU and gets the job done.