(Posting on behalf of my friend and scripter I will relay information for them!)
Note: I’m experienced in programming but not Roblox’s platform. I’m trying to edit a game engine someone else wrote.
The code has one looping song for when in the avatar editing menu and a second song for when the player spawns in. Both songs are only playing on the server side of the game and not the client side. This means that whenever a new player joins the game, the menu music overlaps with the main music for a few seconds, and whenever a player spawns in, the music stops for a few seconds and restarts (again, for everyone in the server).
There’s three scripts that control the music. One to control the menu music when the player joins and stops it when the player spawns in. One starts the main music when the player spawns in. The third is tied to the GUI and turns off the music (this one does only work on the client-side). The scripts are organized like this because they do other things with initialization and spawning in the player. All three are local scripts. The first two (initialization and spawning in) are located under StarterPlayerScripts. The last one is in StarterGui.
Things I’ve tried:
-Moving the music files to SoundService, StarterPlayer, or ReplicatedStorage
-Taking the audio out of the SoundGroup they’re in
Code in the initialization script:
local MenuMusic = game.ReplicatedStorage.Music:WaitForChild("MusicGroup"):WaitForChild("MenuMusic")
player.CharacterAdded:Connect(function(char)
MenuMusic.Volume = 0.5
if not player.PlayerGui:WaitForChild("LoadingScreen", 1) and not MenuMusic.IsPlaying then
player.MenuMusic:Play()
end
end)
Code in the spawning script:
local MenuMusic = game.ReplicatedStorage.Music:WaitForChild("MusicGroup"):WaitForChild("MenuMusic")
local GameMusic = game.ReplicatedStorage.Music:WaitForChild("MusicGroup"):WaitForChild("GameMusic")
player.CharacterAdded:Connect(function(char)
if IsSpawningValue and IsSpawningValue.Value == true then
IsSpawningValue.Value = false
--stop music, keep at the end
local T = tick()
local t = 0
while t < 2 do
MenuMusic.Volume = (1 - t/2)*0.3
t = tick() - T
wait()
end
MenuMusic:Stop()
GameMusic.Volume = 0.3
GameMusic:Play()
else
if GameMusic.IsPlaying then
local T = tick()
local t = 0
while t < 2 do
GameMusic.Volume = (1 - t/2)*0.3
t = tick() - T
wait()
end
GameMusic:Stop()
end
end
end)
Code in the GUI script:
local MusicGroup = game.ReplicatedStorage.Music:WaitForChild("MusicGroup")
script.Parent.Activated:Connect(function()
if script.Parent.BackgroundColor3 == Color3.fromRGB(170, 0, 0) then
MusicGroup.Volume = 1
script.Parent.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
else
MusicGroup.Volume = 0
script.Parent.BackgroundColor3 = Color3.fromRGB(170, 0, 0)
end
end)
Any help is appreciated!