function CharacterRealism.MountMaterialSounds(h,G)local F=G.Parent local e=F and F:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116",10)if not(e and e:IsA("\066\097\115\101\080\097\114\116"))then return end Util:PromiseChild(e,"\082\117\110\110\105\110\103",function(F)if not F:IsA("\083\111\117\110\100")then return end local o=Instance.new("\078\117\109\098\101\114\086\097\108\117\101")o.Name="\079\108\100\080\105\116\099\104"o.Parent=F o.Value=1 local function m(h,m)if m.Name:find("\082\117\110\110\105\110\103")then while G:GetState()==m do local h=G.HipHeight if G.RigType.Name=="\082\054"then h=2.8 end local m=h/3 local B=(e.Velocity*XZ_VECTOR3).Magnitude local P=((B-4)/12)*m F.Volume=math.clamp(P,0,1)local c=o.Value/((m*15)/B)F.Pitch=c RunService.Heartbeat:Wait()end end end local function B()local e=h.Sounds.Concrete local o=G.FloorMaterial.Name if not h.Sounds[o]then o=h.MaterialMap[o]end if h.Sounds[o]then e=h.Sounds[o]end F.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..e end local P=G:GetPropertyChangedSignal("\070\108\111\111\114\077\097\116\101\114\105\097\108")P:Connect(B)F.EmitterSize=1 F.MaxDistance=50 B()G.StateChanged:Connect(m)m(nil,Enum.HumanoidStateType.Running)end)end
-- Mounts the custom material walking sounds into the provided
-- humanoid. This mounting assumes the HumanoidRootPart is the
-- part that will be storing the character's "Running" sound.

function CharacterRealism:MountMaterialSounds(humanoid)
	local character = humanoid.Parent
	local rootPart = character and character:WaitForChild("HumanoidRootPart", 10)

	if not (rootPart and rootPart:IsA("BasePart")) then
		return
	end

	Util:PromiseChild(rootPart, "Running", function(running)
		if not running:IsA("Sound") then
			return
		end

		local oldPitch = Instance.new("NumberValue")
		oldPitch.Name = "OldPitch"
		oldPitch.Parent = running
		oldPitch.Value = 1

		local function onStateChanged(old, new)
			if new.Name:find("Running") then
				while humanoid:GetState() == new do
					local hipHeight = humanoid.HipHeight

					if humanoid.RigType.Name == "R6" then
						hipHeight = 2.8
					end

					local scale = hipHeight / 3
					local speed = (rootPart.Velocity * XZ_VECTOR3).Magnitude

					local volume = ((speed - 4) / 12) * scale
					running.Volume = math.clamp(volume, 0, 1)

					local pitch = oldPitch.Value / ((scale * 15) / speed)
					running.Pitch = pitch

					RunService.Heartbeat:Wait()
				end
			end
		end

		local function updateRunningSoundId()
			local soundId = self.Sounds.Concrete
			local material = humanoid.FloorMaterial.Name

			if not self.Sounds[material] then
				material = self.MaterialMap[material]
			end

			if self.Sounds[material] then
				soundId = self.Sounds[material]
			end

			running.SoundId = "rbxassetid://" .. soundId
		end

		local floorListener = humanoid:GetPropertyChangedSignal("FloorMaterial")
		floorListener:Connect(updateRunningSoundId)

		running.EmitterSize = 1
		running.MaxDistance = 50

		updateRunningSoundId()
		humanoid.StateChanged:Connect(onStateChanged)

		onStateChanged(nil, Enum.HumanoidStateType.Running)
	end)
end
