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
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?
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.