How do you detect the floor the humanoid is standing on?

I want to be able to detect the floor that a player is standing on.

The solution I came up with is by making a raycast that goes from the HumanoidRootPart downwards, and it works, but there’s one slight problem. When I stand on a ledge of a part, it doesn’t detect a floor, even though I’m standing.

You can see in the two screenshots what I mean:

Detects floor:

Doesn’t detect floor although player is standing:

How do I make it so it detects the floor no matter if you are on the ledge of the floor or not?

1 Like

you can use Humanoid.FloorMaterial property

if Humanoid.FloorMaterial == "Air" then
    print("The humanoid is floating / falling")
end
1 Like

To get the floor your standing on, try getting the parts the character’s legs are touching. You can use the GetTouchingParts() method for this.

local parts = {
unpack(player.Character["Left Leg"]:GetTouchingParts()),
unpack(player.Character["Right Leg"]:GetTouchingParts())
}
2 Likes

This is unfortunately not what I wanted. I wanted to get the part, not the material. Thanks for your help though!

Alright, I’ll test this out and come back with the results I got. Thanks!

1 Like

With @bluebxrrybot 's idea (How do you detect the floor the humanoid is standing on? - #3 by bluebxrrybot) i was able to write this script. Thanks alot!

repeat wait() until game.Players.LocalPlayer.Character
local rootpart =  game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

local floordetector = Instance.new("Part") 
floordetector.Size = Vector3.new(1.95, 0.003, .95)
floordetector.Transparency = 0
floordetector.CanCollide = false
floordetector.Parent = workspace

game:GetService("RunService").RenderStepped:Connect(function()
	floordetector.CFrame = rootpart.CFrame + rootpart.CFrame.UpVector * (-3 - humanoid.HipHeight)
	local connection = floordetector.Touched:Connect(function() end)
	local parts = {
		unpack(floordetector:GetTouchingParts()),
	}
	connection:Disconnect()
	for i, floor in parts do
		if floor.CanCollide == true then
			--code
			break
		end
	end
end)

This was actually my second idea, but I didn’t bother saying it. I suggest using a weld instead of setting the CFrame of it every render step.
Also, you might need to connect an empty function to the Touched event of the floor detector, so GetTouchingParts can be the most reliable.

1 Like

I don’t really know how to use welds so this was basically my only solutions, but I’d say that using a weld would work too. Also I did add a touched event because without it, it wouldn’t have worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.