I need help with my footstep module

I have this footstep module that works and is very cool, but it only plays one sound per material. I want it to play random specific footstep sounds. I’ve looked everywhere but I can’t find a good tutorial anywhere.

Here is the module:

local MaterialSounds = 
	{
		[Enum.Material.Grass] = "rbxassetid://9064714296",
		[Enum.Material.Metal] = "rbxassetid://9064974448",
		[Enum.Material.DiamondPlate] = "rbxassetid://9064974448",
		[Enum.Material.Pebble] = "rbxassetid://9064853890",
		[Enum.Material.Wood] = "rbxassetid://9064822808",
		[Enum.Material.WoodPlanks] = "rbxassetid://9065052688",
		[Enum.Material.Plastic] = "rbxassetid://9065069004",
		[Enum.Material.SmoothPlastic] = "rbxassetid://9065069004",
		[Enum.Material.Sand] = "rbxassetid://944090255",
		[Enum.Material.Brick] = "rbxassetid://9048713108",
		[Enum.Material.Cobblestone] = "rbxassetid://9048713108",
		[Enum.Material.Concrete] = "rbxassetid://9048713108",
		[Enum.Material.CorrodedMetal] = "rbxassetid://4871517596",
		[Enum.Material.Fabric] = "rbxassetid://4981969796",
		[Enum.Material.Foil] = "rbxassetid://4981969796",
		[Enum.Material.ForceField] = "rbxassetid://4981969796",
		[Enum.Material.Glass] = "rbxassetid://944075408",
		[Enum.Material.Granite] = "rbxassetid://9065069004",
		[Enum.Material.Ice] = "rbxassetid://138214900",
		[Enum.Material.Marble] = "rbxassetid://9065069004",
		[Enum.Material.Neon] = "rbxassetid://944075408",
		[Enum.Material.Slate] = "rbxassetid://944075408",
		[Enum.Material.Mud] = "rbxassetid://6361856730",
		[Enum.Material.Snow] = "rbxassetid://10787645847",
		[Enum.Material.Water] = "rbxassetid://9126195782"
	}

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local FootStepsSound = HumanoidRootPart:WaitForChild("Running")

Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	local FloorMaterial = Humanoid.FloorMaterial
	local Sound = MaterialSounds[FloorMaterial]
	if Sound then
		FootStepsSound.SoundId = Sound
	else
		FootStepsSound.SoundId = "rbxassetid://9048713108"
	end
end)

FloorMaterial is the Enum.Material that the player is standing on. That is why it only runs once, since FloorMaterial only updates when you step on a object with a different FloorMaterial.

You could use the velocity of the player (for example) to regulate the footstep sounds

Even better connect with a function to markers in the walking animation so it matches with the walking animation.

I would say the main issue is the fact that you are not Playing the sound, or its not looped.

Roblox default footsteps system just loops one audio and resumes it every time you start walking
and switches sound ids depending on material.

no what i mean is that i want it to be multiple random sounds instead of one long sound, not just to match the animation
like these:




(Source like footsteps)

local sounds = {"abc", "123", "asdfasdfasdf"} -- just example strings (this works with anything)
local randomSound = sounds[math.random(1,#sounds)] -- choose something random from the sounds table

print(randomSound) -- gives a random sound

what does the 1 and #sounds mean?

#sounds is length of the sounds table. The code @happya_x shared you gets a random sound from a list and prints it to the output.

what aboutt the 1 (ignore this, this is to avoid minimum of characters

math.random(1,#sounds) gets a random index from 1 (where arrays start) and #sounds, the length of the table.
When you do sounds[math.random(1,#sounds)], you get a random sound from list index 1 to list index #sounds

The other replies you got have very good answers, I’ll try to explain what they mean.

local RandomSound = sounds[math.random(1, #sounds)]
in this case, “sounds” would be an array / table of all of those individual sounds you showed an example of. math.random returns a random one of those sounds in the form of the variable “RandomSound”
Then you could play that sound in any way you like.

but what does the 1 meannnnnnnnn

math.random(x, y)
x is the minimum number
y is the maximum number
in this case #sounds is the LENGTH of the sounds folder
So lets say you have a table of 6 sounds
the math.random will return a random number between 1 and 6, including 1 and 6

math.random can also be used with negative numbers, but the smaller number must come first:

local TestNumber = math.random(-6, 6)

returns a random number between (and including) -6 and 6

I suppose you could just turn this table into a library with all the sounds you want for each material placed alongside the material.

local MaterialData - {
Material1 = {
Name = "Grass",
ID = "rbxassetid://9064714296",
SoundName = --add name,
SoundID = --roblox sound id,
--any other data

},
--End Grass Data
}