How do I make my walk-sound play a different sound after a footstep has been completed?

So basically, I want my walk-sounds to be randomized by the sounds in this table below, but for some reason it plays the same sound over and over again until you decide to die, and maybe it might play a different sound. But that is not what I’m looking for.

local RUN_S = {'rbxassetid://167448699', 'rbxassetid://6876504577'}

RUN.SoundId = RUN_S[math.random(1, #RUN_S)]
RUN.Pitch = 1

The scripting above is what I typed.

1 Like

Arrays actually start at index 0, so the random number thing should also start at 0.

EDIT: I was wrong, apparently. (Why on earth is Lua different on Roblox and MediaWiki?)

2 Likes

done that, no change.

local RUN_S = {'rbxassetid://167448699', 'rbxassetid://6876504577'}

RUN.SoundId = RUN_S[math.random(0, #RUN_S)]
RUN.Volume = 0.1
2 Likes

That’s weird. I assumed this was only a snippet of your code, you’re running this on every footstep right?

2 Likes

every footstep should play a randomized sound from the table, after each footstep sound has been completed.

2 Likes

So you do have the random footstep selection inside a function that is called with each footstep? Can you show your whole code?

2 Likes

Arrays do not start at index 0 for lua if the index is not defined. You seem to be confusing coding languages with each other.

3 Likes

print the math.random thing
just to know if it repeats same thing

2 Likes

Huh, it does on MediaWiki. I’ve had to deal with many a bug from accidentally choosing index 1 instead of index 0 there.

2 Likes

MediaWiki is not a verified or trusted source to be disseminating information when it comes to Lua. You should be using the DevForum or the actual documentation website.

So Roblox’s Lua is completely different from MediaWiki’s Lua?

Man, and I thought every coding language having a different version of regex was annoying.

That is the whole code lol, everything else is not relative to it.

That’s your problem. It’s only running once, so it never selects a new random sound.

1 Like

Roblox uses Luau which is built off of Lua whereas MediaWiki is actually covering the Lua language itself.

It’s not offtopic considering it’s in response to false information that was accidentally spread which is related to the main post. You can report me if you feel as though you’re right.

while true do should do the trick, am I wrong?

You’ll want a task.wait() in there to slow it down, but technically, yeah…but I suggest instead running it with each footstep, so that it isn’t lagging your game by running constantly when it doesn’t need to. You can do this using keyframe markers, running it the moment a footstep happens and then playing the sound.