Footstep sound changer by material

Hello there, I have come to you open sourcing one of my projects.

I have come open sourcing it for the reason of many people asking me for it, so I will redirect them to this post right here on ConnectDev.

To start off, you will need to have few materials on your map. Any material such, plastic, grass, air, brick etc…
When that’s ready you will need to create a SoundGroup object placed in SoundService called Footsteps.
Such displayed below
image

Then, we would want to make our sounds. So, to achieve that, you will need to create sounds in the SoundGroup object named the material name then set the SoundId to your sound’s Id.
Here’s an example of what I have in my game.


Also make sure to set a Sound called “nil Sound” for that will make no sound when your material does not exist in the Footsteps SoundGroup
image

After that is setup, we are ready to code! Yay!

So for the coding section, start off by placing a LocalScript in StarterCharacterScripts (name does not matter). So if you are not aware, there is a Sound set in the HumanoidRootPart by Roblox which is used for the character’s footsteps.

Then you would paste in this code below in the LocalScript.

local Character = script.Parent;
local HumanoidRoot = Character:WaitForChild("HumanoidRootPart");
local RunningSound = HumanoidRoot:WaitForChild("Running");
local FootstepsSoundGroup = game:GetService("SoundService"):WaitForChild("Footsteps");
local Humanoid = Character:WaitForChild("Humanoid");

Humanoid.Changed:Connect(function(prop)
	if (prop == "FloorMaterial") then			
		if (FootstepsSoundGroup:FindFirstChild(Humanoid.FloorMaterial) == nil) then
			RunningSound.SoundId = FootstepsSoundGroup:WaitForChild("nil Sound").SoundId;
			RunningSound.PlaybackSpeed = FootstepsSoundGroup:WaitForChild("nil Sound").PlaybackSpeed;
			RunningSound.Volume = FootstepsSoundGroup:WaitForChild("nil Sound").Volume;
		else
			RunningSound.SoundId = FootstepsSoundGroup:WaitForChild(Humanoid.FloorMaterial).SoundId ;
			RunningSound.PlaybackSpeed = FootstepsSoundGroup:WaitForChild(Humanoid.FloorMaterial).PlaybackSpeed;
			RunningSound.Volume = FootstepsSoundGroup:WaitForChild(Humanoid.FloorMaterial).Volume;
			print(Humanoid.FloorMaterial); --Checking
		end;
	end;
end);

Hope this has contributed to your development :wink:
Crediting me is not needed.

Brief overview on what you must know to achieve

So this section is used if you were wanting to understand the code in detail.

First off, you must know that the HumanoidRootPart has sounds in it when game runs.
image
There are a few sounds in there, but no need to worry. We’re just concentrating on the Running one currently.

The Humanoid has a property which indicates it’s current material it is standing on. I have used that to detect which part the Humanoid is standing on with a changed event which fires every time a property in the Humanoid changes.

humanoid.Changed:Connect(function(prop)
    if prop == "FloorMaterial" then
        print(humanoid.FloorMaterial)
    end
end)

That would be basically what is the main part of my code. As for the rest is just getting the sound Id from the SoundGroup and setting it to the HumanoidRootPart’s Running Sound Id.

If you have any suggestions, let me know :slight_smile:

4 Likes

This could be a good model, you can make walking sounds for certain terrains and add it into a model, after that i could advertise the model for you.

Ooo I appreciate the offer, but I don’t really think I would want to advertise something like this as it’s nothing too broadly used in games.
I really like your suggestion making into a model, I’ll do that now.

This actually is really nice. Never understood the reason for “SoundService”! :laughing:

1 Like

dawg!!! he ll yeah!!!

1 Like

Welcome to the community