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

How do I make random music play?

Asked by 5 years ago

I'm trying to make random music play in my game. Not a specific order for the music to play just random. I've tried so many different ways and none work I am confusion.

0
Do you have a list of music for the players to listen to? if you do and they are under a single parent, you can use math.random() to pick a sound and iterate through the parent:GetChildren() table, if the index == random then play the music SerpentineKing 3885 — 5y
0
I have the SoundId of all the songs and I have math.random() in the script. It plays one random song then just stops. therealninetailz 0 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
01local Ids = {158849566,1238143270,412393959} --id table
02 
03local Music = workspace.Sound.Music
04 
05local IdChosen
06local function RandomId()
07    local Id = math.random(3) --number of ids in table
08    IdChosen = Ids[Id]
09end
10 
11RandomId()
12 
13print(IdChosen)
14 
15Music.SoundId = "rbxassetid://"..IdChosen
View all 24 lines...

this way sould stop it from repeating a song

Ad
Log in to vote
0
Answered by 5 years ago
01local overallmusic = game.Workspace.OverallMusic --this is the sound that will be changed/updated
02local RunSer = game:GetService("RunService") --checks per frame
03local music = {} --Just put a sound id in here, make sure to include "," when adding multiple
04RunSer.Heartbeat:Connect(function()
05    if overallmusic.Playing == false then
06        local musicpick = music[math.random(1,#music)] --this gets a random song from the music table
07        overallmusic.SoundId = "rbxassetid://"..musicpick --applies the chosen song
08        overallmusic.TimePosition = 0 --resets the time
09        overallmusic:Play()
10    end
11    wait()
12end)

Hope this helps! :)

0
Ok Player1_Joined I love you thank you so much. therealninetailz 0 — 5y

Answer this question