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

How to make this play random music?

Asked by
TechModel 118
3 years ago

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()

0
i don't see a random math method in the script... Gmorcad12345 434 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
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()

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. ChristianTRPOC 64 — 3y
0
I added my own ID's but there's no music playing TechModel 118 — 3y
0
Just saying that I fixed line 16, you forgetting the space for the "=" but it still doesn't work TechModel 118 — 3y
0
The space doesn't matter, where is the script located? ChristianTRPOC 64 — 3y
0
It's a Local script in ReplicatedFirst, parented with the LoadingGUI and sound. TechModel 118 — 3y
Ad

Answer this question