Randomized FootStep Sounds on Floor Material

Hello, I would like some advice on how I would be able to add in multiple sound IDs for the wood,concrete, etc. floor materials, then have them play at random as a character walks. This way you don’t get the same repetitive loop playing over and over as a character walks. I would really like some help on how I would be able to achieve this. I’ve tried searching google for advice on this and haven’t been able to find anything helpful. Thank you.

This should help you.

1 Like

Also you can create a table of sounds then do math.random to pick a random one.

How would I do this? For example in the script you showed. How would I make “Enum.Material.Grass” have multiple IDs? Please forgive me as I haven’t worked with tables on Lua but would really like to learn

Like create a table with Sound IDs in it.

local grassSounds = {"Sound ID", "Sound ID", "Sound ID"}

To get a random sound you can do

local randomSound = grassSounds[math.random(1, #grassSounds)]

I tried it like this, but it didn’t seem to work, and it just ends up playing the first ID of the wood material in a fast loop…

local Player = game.Players.LocalPlayer
local Character = Player.Character

local DefaultSound = Character.HumanoidRootPart:WaitForChild("Running").SoundId

local WoodTable = {
	[Enum.Material.Wood] = "rbxassetid://4085869219", "rbxassetid://4085869581"
}

local randomSound = WoodTable[math.random(1, #WoodTable)]

local Assets = {"rbxassetid://4085869219","rbxassetid://4085869219"}
game:GetService("ContentProvider"):PreloadAsync(Assets)

Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	local FloorMaterial = Character.Humanoid.FloorMaterial
	if WoodTable[FloorMaterial] then
		Character.HumanoidRootPart.Running.SoundId = WoodTable[FloorMaterial]
	else
		Character.HumanoidRootPart.Running.SoundId = DefaultSound
	end
end)

I have never done this before so I can’t really help that much. Try looking up youtube videos on it. I see a few about what you are trying to do.

Also the reason it may play so fast is because the sound is very short.

It’s alright thank you for trying though. And I’ve tried youtube and every video I’ve seen just sticks to one sound ID for their tutorial, rather than multiple.

Try putting the

local randomSound = WoodTable[math.random(1, #WoodTable)]

in the function so every time the function fires it randomizes.

It seems to still play the same sound in a loop rather than alternating randomly between them as I walk unfortunately…

Barely logged in today and just saw this. This actually helped, thank you very much!