How to detect what part is the humanoid walking in

  1. What do you want to achieve? i want to detect what part is the humanoid is walking roblox

  2. What is the issue? I don’t know how I can achieve it

  3. What solutions have you tried so far? I tried to use the Humanoid floormaterial but I could not achieve it

Explaining better:
I need to know what part is the player walking in without using the “Touch” event on separate parts, like I need to detect what part is the player walking without needing to insert a lot of scripts in different parts

6 Likes

You can raycast while the player is moving and then get the raycast result which is the part they are walking on

game:GetService("RunService").Heartbeat:Connect(function(dt)
     if humanoid.MoveDirection.Magnitude > 0  then
        local result = workspace:Raycast(root.Position, root.CFrame.UpVector * -5)
        if result then
           local partWalkingOn = result.Instance
        end
     end
  end)
2 Likes

You can use a raycast to do that

local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
local RayCast = game.Workspace:Raycast(game.Players.LocalPlayer.Character.HumanoidRootPart.Position, Vector3.new(0, -(game.Players.LocalPlayer.Character:GetExtentsSize().Y / 2 + 0.15), 0), RaycastParams)
if RayCast ~= nil and RayCast.Instance ~= nil then
    print(`Player is standing on {RayCast.Instance.ClassName}`)
else
    print("Player is not standing on anything")
end
2 Likes

this script is buggy, i was walking on the baseplate and it said i was standing on nothing

1 Like

i need to detect even when the player is idle and not walking

2 Likes

Would using humanoid floor material work for you?

1 Like

negative, i tried it i need to detect what part is the humanoid walking in

1 Like

just removed the movedirection magnitude check

game:GetService("RunService").Heartbeat:Connect(function(dt)
     local result = workspace:Raycast(root.Position, root.CFrame.UpVector * -5)
     if result then
        local partOn = result.Instance
     end
end)
1 Like

it’s giving me the character when printing it, i tried to add a check

	local result = workspace:Raycast(root.Position, root.CFrame.UpVector * -5)
	if result and result.Instance.Parent ~= character then
		local partOn = result.Instance
                print(partOn.Name)
	end

also relax it’s not the heartbeat thing ok?

1 Like

Are you useing the RaycastParams from above to Exclude your character?

2 Likes

i don’t know how to use raycast, sorry, that’s why i came here to ask for help

2 Likes

local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {root.Parent} --or if you have a character.
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(root.Position, root.CFrame.UpVector * -5,RaycastParams)
if result  then
	local partOn = result.Instance
	print(partOn.Name)
end
1 Like

attempt to modify a readonly table i got this error

1 Like

I hate to spoonfeed someone but Im bored rn so here take this
Paste into starterplayerscripts

local rp = RaycastParams.new()
rp.FilterType = Enum.RaycastFilterType.Exclude
rp.RespectCanCollide = true

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
rp.FilterDescendantsInstances = {char}

plr.CharacterAdded:Connect(function(newChar)
	char = newChar
	rp.FilterDescendantsInstances = {char}
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if char:FindFirstChildOfClass("Humanoid"):GetState() ~= Enum.HumanoidStateType.Dead then
		local ray = workspace:Raycast(char.PrimaryPart.Position, Vector3.yAxis * -100, rp)
		if ray then
			print(ray.Instance:GetFullName())
		end
	end
end)

thanks, it worked, i’m really thankful.

1 Like

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