Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make this play a random sound everytime?

I have this which is supposed to play a random sound each time:

local soundtable = {
	
	"1",
	"2",	
	"3",
	"4",
	"5"
	
}

...

[Enum.HumanoidStateType.Dead] = function()
	stopPlayingLoopedSounds()
	math.randomseed(os.clock())
	random = math.random(1,5)
	playSound((soundtable[random]))
end,

And the error I get is

Players.JLW1009.PlayerScripts.RbxCharacterSounds:77: attempt to index nil with 'TimePosition'

4 comments

0

This isn't enough to explain your issue. Can you give us the actual code at which the error occurs?

0

Not really worth it to put the actual code, so I'll just tell you: Basically calls TimePosition = 0 and plays the sound.

0

Oh, I overlooked. Perhaps the Sound is being created but not parented, or it just doesn't exist. Check your hierarchy.

0

Actually, I'm just wondering, Can you edit one question and replace it with another?

1 answer

Just Ditch the entire soundtable idea and do something like this:

Dead1 = {
	SoundId = "1"
},

Dead2 = {
	SoundId = "2"
},

---

Dead9 = {
	SoundId = "9"
},

Dead10 = {
	SoundId = "10"
},

This discussion is preserved as it was. New answers, comments, and votes are closed.