What do you want to achieve? i want to detect what part is the humanoid is walking roblox
What is the issue? I don’t know how I can achieve it
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
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)
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
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)
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
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
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)