hopefully easy script question
hello! m trying to combine two script functions that work by themselves but cant seem to figure it out. script 1 is linked to all my other ui elements, it plays the single track BgMusic, and stops it when pressing the mute button in settings. Script 2 is a random playlist, that calls different sounds in a group and plays them in a random order.
how do i use this code to edit script 1 to pull the random songs from SFX instead of just looping the Bg music. Thanks! sorry total noob here
SCRIPT 1
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Remotes = ReplicatedStorage.Remotes.UI
local SettingsConfig = require(ReplicatedStorage.Configs.SettingsConfig)
local StateManager = require(ReplicatedStorage.Client.State)
local function PlayMusic()
local isMusicEnabled = SettingsConfig.IsSettingActive("Music", StateManager.GetData())
if isMusicEnabled then
local isAlreadyPlaying = SoundService.SFX.BgMusic.Playing
if not isAlreadyPlaying then
SoundService.SFX.BgMusic:Play()
end
else
SoundService.SFX.BgMusic:Stop()
end
end
PlayMusic()
Remotes.UpdateSetting.OnClientEvent:Connect(function(setting)
local isMusicSetting = setting == "Music"
if isMusicSetting then
task.delay(0, PlayMusic)
end
end)
SCRIPT FOR RANDOM PLAYLIST STANDALONE
local SoundGroup = game.SoundService.SFX -- Change SoundGroup to whatever you named your SoundGroup
local Playlist = {
SoundGroup.Sound1,
SoundGroup.Sound2,
SoundGroup.Sound3,
\-- Add more sounds if needed
}
local function PlayRandomSound()
local randomIndex = math.random(1, #Playlist)
local Sounds = Playlist\[randomIndex\]
if Sounds then
Sounds:Play()
Sounds.Ended:Wait()
end
end