Hi DevForum, for my game menu, is it possible to have music randomly selected to play? I have 5 songs that I would like to put into my game menu, anytime, somebody joins one of those 5 songs will play randomly.
I am just asking if it is possible, I am not asking if someone can do it for me. I am pretty sure that is against the rules.
Yes it’s possible to do, and quite simple. Create an array with the SoundIDs you want to be played, and select randomly from that table:
local Player = game:GetService("Players").LocalPlayer
local MusicIDs = {
1111111111;
2222222222;
3333333333;
}
local Sound = Instance.new("Sound")
Sound.Parent = Player
Sound.Looped = true -- Delete if you don't want the music to loop
Sound.SoundId = "rbxassetid://".. MusicIDs[math.random(1, #MusicIDs)]
Sound:Play()