Hi everyone and Happy New Year! I hope you guys can help me on this one.
So I’m trying to make a system that produces a footstep sound every step I take based on the material you are on, but I’m having some issues with the SoundId. I got multiple sounds Id for each materials stored in a module script, this is so the footsteps are not repetitive and annoying like the default Roblox walking sound.
I’m gonna take for example the material “Fabric”, here is how I stored it in my module script :
I got the idea to put a animation event called “Footstep” every time one of the feet makes contact with the ground in each of my animations. So here is my script for the running animation :
local footsteps = require(script:WaitForChild("Footsteps"))
anim["frontrun"]:GetMarkerReachedSignal("Footstep"):Connect(function()
if humanoid.WalkSpeed > 20 then
local material = footsteps.materialMap[humanoid.FloorMaterial]
local soundId = footsteps.sounds[math.random(1, #material)]
local sound = Instance.new("Sound")
sound.Name = "FootstepSound"
sound.Parent = root
sound.SoundId = soundId
print(sound.SoundId)
end
end)
My only problem is that I receive nil for the sound Id.
local material=string
local soundid=footstep.sounds[math.random(1,#length_of_string)] --6
--(length_of_string is 6 or so, there are 4 elements in footsteps.sounds["Fabric"]
what probably should happen (at least for it to not error):
local soundid=footsteps.sounds[material]
sound.SoundId=soundid[math.random(#soundid)]
(this will still most likely error if a humanoid steps on a material that isnt in the material table, you can fix this by actually checking that)
Thank you it worked! And also because I don’t have a sound for every material well I had already assigned those to a material similar that has a sound id :