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

How do I make a random audio play?

Asked by 9 years ago

I have a multiplayer zombie game project. As soon as zombies/humans win, a music plays. It's either winning(human) or losing(zombie) music.

How do I make random music play when one of the actions happen?

2 answers

Log in to vote
2
Answered by 9 years ago

Assign each music track a number then generate a random number and when the number is selected use that number to play the track assigned said number

random number generator taken from roblox wiki

for _ = 1,1 do
    print(math.random(10))
    wait(1)
end

EXAMPLE SCRIPT

local 1 = track1
local 2 = track2
local 3 = track3

local track = (math.random(3)) -- put number of tracks where 3 is

it would need some work to get it to work :D but it is the basic idea

0
Thanks. Really helps. ShadowsBeans 0 — 9y
Ad
Log in to vote
1
Answered by
Tynezz 0
9 years ago
local musicids={123456,123456,1234556} --Change these to the music ids you want to play, feel free to add some music
function PickRandomFrom(tab)
return tab[math.random(1,#tab)]
end
local id=PickRandomFrom(musicids)
local music=Instance.new("Sound",game.Workspace)
music.SoundId=id --I'm not sure if it's called SoundId, probably something else
music:Play()

Answer this question