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

How to make this play random music?

This script is for a opening gui and it plays music. I tried using random math method but it seems to not work at all, or just I'm doing it wrong. What I was trying to make is everytime u join, a new sound plays than the same one previously you joined.

local Sound = script.Sound

local GUI = script:WaitForChild("LoadingScreen")
local plr = game.Players.LocalPlayer

GUI.Parent = plr.PlayerGui
script.Parent:RemoveDefaultLoadingScreen()

repeat
	wait(.5)
until game:IsLoaded()

Sound:Play()
Sound.Volume = 1

wait(15)

GUI.Frame:TweenPosition(UDim2.new(0,0,-1.5,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad, 1)

wait(1)

Sound.Volume = .9
wait(.25)
Sound.Volume = .8
wait(.25)
Sound.Volume = .7
wait(.25)
Sound.Volume = .6
wait(.25)
Sound.Volume = .5
wait(.25)
Sound.Volume = .4
wait(.25)
Sound.Volume = .3
wait(.25)
Sound.Volume = .2
wait(.25)
Sound.Volume = .1
wait(.25)
Sound.Volume = .05
wait(.25)
Sound.Volume = .025
wait(.25)
Sound.Volume = .01
wait(.25)
Sound:Stop()

GUI:Destroy()

1 comment

0

i don't see a random math method in the script...

1 answer

local Sound = script.Sound

local GUI = script:WaitForChild("LoadingScreen")
local plr = game.Players.LocalPlayer

GUI.Parent = plr.PlayerGui
script.Parent:RemoveDefaultLoadingScreen()

repeat
    wait(.5)
until game:IsLoaded()

--change id's here
local MusicId = {123456,789012,345678}

Sound.SoundId= MusicId[math.random(1,#MusicId)]


Sound:Play()
Sound.Volume = 1

wait(15)

GUI.Frame:TweenPosition(UDim2.new(0,0,-1.5,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad, 1)

wait(1)

for vv = 1,0,-0.1 do
	Sound.Volume = vv
	wait(.25)
end
Sound.Volume = 0


GUI:Destroy()

5 comments

0

You can add more or less music id's, Explanation: MusicId is a table and we're calling for a value in that table which is either the first, second or third using math.random(). We'll start at 1, and end at how many variables (from #MusicId) are in the table. For example, right now it is 3, so it will go from 1 to 3.

0

I added my own ID's but there's no music playing

0

Just saying that I fixed line 16, you forgetting the space for the "=" but it still doesn't work

0

The space doesn't matter, where is the script located?

0

It's a Local script in ReplicatedFirst, parented with the LoadingGUI and sound.

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