Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a sound ID play randomly from a table?

Asked by 10 years ago
-- I put this stuff here to show just where the Sound is located

Song = Instance.new("Sound")
Song.Parent = Workspace.Bucket
Song.Volume = 100
Song.Looped = false

-- Here's the Assets table

Assets = {143550410,142544487,154072002,150558724,147096633,143620887,148263609,142851579,154237445,142991813,152318857,142301307,157890927,144803449,148324182,146541462,160535179,154741433,142856192,162596497,144003396,144195439,145546010,152536688,162660508,145143628,146058363,148567163,142318459,163404486}
for _, asset in ipairs(Assets) do
Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
end

-- Here's the actual part that needs work

Song.SoundId = Assets[math.random(1,#Assets)]
Song:Play()

What do I need to do to get this working? I want this to play a song randomly.

1 answer

Log in to vote
5
Answered by
TofuBytes 500 Moderation Voter
10 years ago

You were missing the asset for playing the sound. This is what it should look like.

Song.SoundId = "rbxassetid://" ..Assets[math.random(1,#Assets)] --'http://www.roblox.com/asset/?id=' can also be used.
0
Oh der, thanks man! jaytheidiot 60 — 10y
0
No problem! Make sure to accept the answer on the side. TofuBytes 500 — 10y
Ad

Answer this question