How to change an npcs walk sounds?

You need to find sounds yourself to be played out in specific materials. I’ll give you a template script though:

local sounds = {
    Plastic = "rbxassetid://0",
    Metal = "rbxassetis://0"
}
--You need to add your own sound IDs, and fill out all the materials.

local rig = workspace.Rig

while task.wait(0.25) do --We'll use loops for now.
    if rig.Humanoid.MoveDirection.Magnitude > 0 then
        for _,sound in pairs(sounds) do
            if rig.Humanoid.FloorMaterial == Enum.Material[sounds[sound]] then
                print(sound)
            end
        end
    end
end

Tell me if this works.

It still doesn’t work or print anything

My mistake. Let me rephrase that.

Try this:

local sounds = {
    Plastic = "rbxassetid:/0",
    Metal = "rbxassetid://0"
}
--You need to add your own sound IDs, and fill out all the materials.

local rig = workspace.Rig

while task.wait(0.25) do --We'll use loops for now.
    if rig.Humanoid.MoveDirection.Magnitude > 0 then
        if rig.Humanoid.FloorMaterial == Enum.Material.Plastic then
            print("Material: Plastic | SoundId = "..sounds.Plastic)
        end
    end
end

You would have to fill out every condition for every material.

It doesn’t work!, But I made my own version and it works!

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
if not humanoid.RootPart then
	humanoid:GetPropertyChangedSignal("RootPart"):Wait()
end
local root = humanoid.RootPart
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0" --Change 0 to the audio's asset ID.
sound.Parent = root
sound.Looped = true

local function onRunning(speed)
	if speed > 0 then
		if sound.IsPaused then
			sound:Resume()
		else
			sound:Play()
		end
	else
		sound:Pause()
	end
end

humanoid.Running:Connect(onRunning)

The only problem is that if the npc gets stuck it plays the walking sound really fast really quickly, How could I make a debounce?

Let me merge our scripts.

Try this:

local rig = script.Parent
if not humanoid.RootPart then
	humanoid:GetPropertyChangedSignal("RootPart"):Wait()
end
local sound = --The sound.
--You can manually set all the Sound properties in the actual rig's HumanoidRootPart.

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if sound.IsPaused then
			sound:Resume()
		else
			sound:Play()
		end
	else
		sound:Pause()
	end
end)

And I would recommend manually setting the sound in the HumanoidRootPart to free up space.

2 Likes

It works! Thank you so much! Just a little bit of debugging and it works exactly as intended :smiley:

Thank you. I also had slight issues with helping you out, but glad I gave a boost to your journey.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.