Can't create custom sounds for walking in different type of materials

local Humanoid = script.Parent:FindFirstChild("Humanoid")
local walk = script.Parent.HumanoidRootPart:FindFirstChild("Running")

while true do
	wait()
	
	if Humanoid then
		if Humanoid.FloorMaterial == Enum.Material.Grass then
			walk.SoundId = "rbxassetid://6535944474"
			walk.Volume = 2
		end	
			if Humanoid.FloorMaterial == Enum.Material.WoodPlanks then
				walk.SoundId = "rbxassetid://8454543187"
				walk.Volume = 2
			end
	end
end

So, after i’m doing this the song that i put in ID sounds doesnt works, how can i fix that?

You aren’t playing the sounds, just assigning the SoundId.
Also, isn’t Running a property of the Humanoid, not the HumanoidRootPart?

I believe when using sounds you are supposed to load the sounds at the beginning of the script as a variable, then Play() the variable.

Try Searching the forums. I searched ‘different sounds on different materials’ and came up with:

1 Like

In StarterCharacterScripts

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild"Humanoid"
if not humanoid.RootPart then humanoid:GetPropertyChangedSignal"RootPart":Wait() end
local root = humanoid.RootPart
local running = root:WaitForChild("Running") -- SOUND

local materialSounds = { -- PASTE ID'S IN ""
	["Air"] = "", 
	["Asphalt"] = "",
	["Basalt"] = "",
	["Brick"] = "",
	["Cobblestone"] = "",
	["Concrete"] = "",
	["CorrodedMetal"] = "",
	["CrackedLava"] = "",
	["DiamondPlate"] = "",
	["Fabric"] = "",
	["Foil"] = "",
	["ForceField"] = "",
	["Glacier"] = "",
	["Glass"] = "",
	["Granite"] = "",
	["Grass"] = "",
	["Ground"] = "",
	["Ice"] = "",
	["LeafyGrass"] = "",
	["Limestone"] = "",
	["Marble"] = "",
	["Metal"] = "",
	["Mud"] = "",
	["Neon"] = "",
	["Pavement"] = "",
	["Pebble"] = "",
	["Plastic"] = "",
	["Rock"] = "",
	["Salt"] = "",
	["Sand"] = "",
	["Sandstone"] = "",
	["Slate"] = "",
	["SmoothPlastic"] = "",
	["Snow"] = "",
	["Water"] = "",
	["Wood"] = "r",
	["WoodPlanks"] = ""
}

local function onFloorMaterialChanged()
	if humanoid.FloorMaterial then
		running.SoundId = materialSounds[humanoid.FloorMaterial.Name]
	else
		running.SoundId = "" --Default running sound.
	end
end

local floorMaterialChanged = humanoid:GetPropertyChangedSignal"FloorMaterial"
floorMaterialChanged:Connect(onFloorMaterialChanged)
2 Likes

When i put this function to play it plays a lot of times and in the same time

Tryed this one and didnt worked

What hes doing is, he has the walking sounds playing but the volumes are 0, when the player walks in a specific material, the script finds the material walking sound and sets the volume to 2 for it to be heard, but he is also changing the sound id which in changing the sound id, it would stop the sound. I am sure he wont need to change the sound id from the script since he can have all the sounds in the humanoidrootpart and have them named to their material walking sound. I think I might of not explained it well but im on mobile.

He can make a script that creates the walking sounds to the humanoidrootpart with volume 0. When the player walks on a specific material, the script looks for the walking sound of the material and sets the volume to 2.

Thats more of a good way for me to do a walking sound.

If not, it might be because he has the script changing the id while its playing.

So you wont be needing to change the sound id when you can disable the roblox walk sound and have the seperate walking sounds in the humanoidrootpart.

Hope it helped!

1 Like

You are repeating this entire loop over and over. If you keep walking on one material you keep starting the same sound over and over which (I think) overlaps the sound over and over.
You also aren’t setting the sound Volume to 0 for any of the other sounds. Don’t know if the old sound keeps playing though.

1 Like