Detect FloorMaterial

I want to detect and change footsteps/print to the console whenever someone is on a certain Humanoid.FloorMaterial, how would I detect what FloorMaterial the client is standing on as well as constantly change this(I tried to use a .Changed).

1 Like

Simple Answer


Imagine moving your character and creating footprints. When creating the footprint, read the Humanoid.FloorMaterial. Afterwards, with some if statements, create the footprint with designated material.

Signals should be done while moving, not when the FloorMaterial changes.

3 Likes

How would I detect if the player has moved though?

Humanoid.Running:Connect(function(Speed)
    while Speed > 0 do
        --print(Humanoid.FloorMaterial)
    end
end)
1 Like

FloorMaterial detection should only be done as in when the character is moving. Not relevant to have that as a background process if the character isn’t moving.

I’m not sure whether you’re handling this from a LocalScript or a server script, but if you’re doing this from a LocalScript, you can use the handy BindToRenderStep.

Humanoid.Running:Connect(function (speed)
    if speed > 0 then
        RunService:BindToRenderStep("FloorMaterialCheck", Enum.RenderPriority.Character.Value - 5, function()
            if not CurrentFloorMaterial == LastSetFloorMaterial then
                print("Changed")
            end
        end)
    else
        RunService:UnbindFromRenderStep("FloorMaterialCheck")
    end
end)

If you’re doing this on the server, connecting to Stepped should be fine.

2 Likes

Could you explain RunService to me so I can apply it to this script? I don’t understand runservice and the only developer hub article I found on it didn’t exactly explain it but give you information on what the variables for it do.

The most common use for RunService is binding functions to its events so they run at an extremely fast rate - typically for visual effects. RunService exposes functions for identifying game or script context such as whether it’s running under studio or if it’s running on the client or server, and RenderStepped, Stepped, and Heartbeat, which are events that fire somewhere around 60 times per second. Guidelines for when to use each are on the devhub on these events’ respective pages (click on the event’s name).

https://developer.roblox.com/api-reference/class/RunService

3 Likes

I’ll start learning this so I can implement the material script. Thank you for the help @colbert2677, @Operatik and Qqt(already going to receive this because it’s a reply). I’ll mark Colbert as a reply since it gave me most of the script needed.

1 Like