function CharacterRealism.MountMaterialSounds(O,q)local V=q.Parent local d=V and V:WaitForChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116",10)if not(d and d:IsA("\066\097\115\101\080\097\114\116"))then return end Util:PromiseChild(d,"\082\117\110\110\105\110\103",function(V)if not V:IsA("\083\111\117\110\100")then return end local u=Instance.new("\078\117\109\098\101\114\086\097\108\117\101")u.Name="\079\108\100\080\105\116\099\104"u.Parent=V u.Value=1 local function U(O,U)if U.Name:find("\082\117\110\110\105\110\103")then while q:GetState()==U do local O=q.HipHeight if q.RigType.Name=="\082\054"then O=2.8 end local U=O/3 local S=(d.Velocity*XZ_VECTOR3).Magnitude local L=((S-4)/12)*U V.Volume=math.clamp(L,0,1)local a=u.Value/((U*15)/S)V.Pitch=a RunService.Heartbeat:Wait()end end end local function S()local d=O.Sounds.Concrete local u=q.FloorMaterial.Name if not O.Sounds[u]then if not O.MaterialMap[u]then u=O.Sounds.Concrete else u=O.MaterialMap[u]end end if O.Sounds[u]then d=O.Sounds[u]end V.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..d end local L=q:GetPropertyChangedSignal("\070\108\111\111\114\077\097\116\101\114\105\097\108")L:Connect(S)V.EmitterSize=1 V.MaxDistance=50 S()q.StateChanged:Connect(U)U(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
				if not self.MaterialMap[material] then
					material = self.Sounds.Concrete
				else
					material = self.MaterialMap[material]
				end
			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
