The issue is basically in the title, I used a tutorial for this script and people in the comment section had the same issue as I, but the youtuber never fixed the issue. Please help me
It could be hard to read this since it doesnt go in a straight line, but I dont know how to change font size
Please format your code so it’s more readable or just take a screenshot of the script
This is a very simple thing to do and most certainly doesn’t require as many lines as this YouTuber used! This YouTuber is kind of overcomplicating it in my opinion. If I’m correct, you want a certain sound ID to play when the player walks over a certain material. This is achievable in a very small amount of lines!
local running = player.Character.HumanoidRootPart:WaitForChild("Running")
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if humanoid.FloorMaterial == Enum.Material.YourMaterial then
running.SoundId = yoursoundid
end
end)
Alternatively, if you wanted a different sound to play for different materials, you could make a table:
local sounds = {
[Enum.Material.Grass] = "rbxassetid://sound",
[Enum.Material.Mud] = "rbxassetid://sound",
[Enum.Material.Ground] = "rbxassetid://sound",
[Enum.Material.Asphalt] = "rbxassetid://sound",
}
local running = player.Character.HumanoidRootPart:WaitForChild("Running")
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if sounds[humanoid.FloorMaterial] then
running.SoundId = sounds[humanoid.FloorMaterial]
end
end)
Let me know if you have any problems or questions
How would I change the script if I have a list of sounds in SoundService already?
So, each sound has a sound ID. I wouldn’t recommend storing sounds as objects, but rather store the IDs programmatically like in a table in the way that I did. Go into each sound, get the ID (should be a string of numbers) and paste it into the script where I wrote
"rbxassetid://sound"
Replace “sound” with the numbers and where it says Enum.Material.x
change the material to the desired material that you want the sound to play from.
The main floor material in my game is Concrete, so I changed Concrete to the sound I wanted to play, and it didn’t work. Not sure if I typed the script wrong or right,
I haven’t filled in the others yet as I didn’t think I would need to.
What is the output saying? Press F9 to see developer log btw
Touched is not a valid member of Workspace “Workspace”
Didn’t see it before.
Edit: Oh sorry that goes to the teleport Script that sometimes fails in my game also.
There is nothing wrong with it, apparently.
Alright just remember sound isn’t a valid ID so if you walk on anything that isn’t concrete it’ll throw an error
Yeah but the concrete noise didnt play either.
Did you walk on anything that wasn’t concrete? Also did you define humanoid and player?
I don’t know what you mean by defining, but I don’t think I walked on anything that wasnt concrete.
You have to define humanoid by doing
local humanoid = game.Players.LocalPlayer.Character.Humanoid
Also this is a LocalScript right?
Yes, it is a localscript and I will check now if I have done it.
It still isn’t working for some reason, to be honest I don’t know if I have added the script correctly.
You have an extra } after the local sounds table.
i made a script a while ago and just add a localscript in StarterCharacterScripts then use this script
local materialSounds =
{
[Enum.Material.Plastic] = "rbxassetid://507863105",
[Enum.Material.Wood] = "rbxassetid://507863105",
[Enum.Material.WoodPlanks] = "rbxassetid://507863105",
[Enum.Material.Slate] = "rbxassetid://507863105",
[Enum.Material.Concrete] = "rbxassetid://507863105",
[Enum.Material.Metal] = "rbxassetid://507863105",
[Enum.Material.CorrodedMetal] = "rbxassetid://507863105",
[Enum.Material.DiamondPlate] = "rbxassetid://507863105",
[Enum.Material.Foil] = "rbxassetid://507863105",
[Enum.Material.Grass] = "rbxassetid://507863105",
[Enum.Material.Ice] = "rbxassetid://507863105",
[Enum.Material.Brick] = "rbxassetid://507863105",
[Enum.Material.Sand] = "rbxassetid://507863105",
[Enum.Material.Fabric] = "rbxassetid://507863105",
[Enum.Material.Granite] = "rbxassetid://507863105",
[Enum.Material.Marble] = "rbxassetid://507863105",
[Enum.Material.Pebble] = "rbxassetid://507863105",
[Enum.Material.Cobblestone] = "rbxassetid://507863105",
[Enum.Material.SmoothPlastic] = "rbxassetid://507863105",
[Enum.Material.Neon] = "rbxassetid://507863105",
[Enum.Material.Glass] = "rbxassetid://507863105",
[Enum.Material.ForceField] = "rbxassetid://507863105",
[Enum.Material.Asphalt] = "rbxassetid://507863105",
[Enum.Material.Basalt] = "rbxassetid://507863105",
[Enum.Material.CrackedLava] = "rbxassetid://507863105",
[Enum.Material.Glacier] = "rbxassetid://507863105",
[Enum.Material.Ground] = "rbxassetid://507863105",
[Enum.Material.LeafyGrass] = "rbxassetid://507863105",
[Enum.Material.Limestone] = "rbxassetid://507863105",
[Enum.Material.Mud] = "rbxassetid://507863105",
[Enum.Material.Pavement] = "rbxassetid://507863105",
[Enum.Material.Rock] = "rbxassetid://507863105",
[Enum.Material.Salt] = "rbxassetid://507863105",
[Enum.Material.Sandstone] = "rbxassetid://507863105",
[Enum.Material.Snow] = "rbxassetid://507863105",
[Enum.Material.Water] = "rbxassetid://507863105"
}
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local footstepsSound = hrp:WaitForChild("Running")
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
local floorMat = humanoid.FloorMaterial
local soundOfMat = materialSounds[floorMat]
if soundOfMat then
footstepsSound.SoundId = soundOfMat
end
end)
you can se after the material something like [Enum.Material.Sandstone] = “rbxassetid://507863105”, the numbers at the end is the sound id this is only a grass walk sound effect. You can customize them all if you want to.