Music for loading screen and main menu

Hello everyone! I made a game with a Loading Screen and main menu. I wanted to add the music when the game starts, and then it will automatically stop when the player presses the play button. I tried to do that but without success…someone know how to do that?

2 Likes

You can put the music to automatically player when the player joins by just setting the Playing property of the music to true, and then in a localscript in the button itself, you could make it so when you click the button, it references the music where you placed it (Ideally in ReplicatedStorage), and just stop it. Since you stopped it locally, it will continue for others who didn’t press play yet. I think that should work

2 Likes
local button = script.Parent
local music = button.Music

music:Play()

button.MouseButton1Down:Connect(function()
music:Stop()
end)
2 Likes

Okay thanks guys it worked :slight_smile: But is there like a way to add a Fade out to the music? Cause i don’t like when the music stops suddenly

You could make a loop that lowers the volume of the music to 0 before stopping

local music = --Your music

for i = music.Volume, 0, -0.05 do
	music.Volume = i
	wait()
end
music:Stop()

Is an example of what you could do, there’s also an example using TweenService mentioned here

1 Like

RobloxScript

So for now I’ve written this script. Where do I have to add the part of script for the fade out?

1 Like

In your MouseButton1Down event, put

for i = music.Volume, 0, -0.05 do
	music.Volume = i
	wait()
end

Above music:Stop()

3 Likes

Ok thank you so much it worked!

2 Likes

Anytime! if you have anymore issues don’t be afraid to make another post!

1 Like