How to make music on intro fade out?

Hello,
I have been working on an intro gui for my game.
this is it so far:

(it didnt upload it was stuck at 50%) sorry.

So far its good. I just need to replace my game name with my logo and a few other improvements.
I have been wondering on how I can fade out the music at the end, instead of it stopping immediately.

I am not the best scripter, but I do try my best. However, I just don’t know how to do this one.

4 Likes

You would call the Sound object and start changing it’s volume. You could do that by using a for i loop. Example:

local Sound = script.Parent

for i = 0, 1, -0.05 do
    Sound.Volume = I
    wait(0.5)
end
4 Likes

TweenService would work fine.

TweenService:Create(sound,TweenInfo.new(1),{Volume = 0}):Play()
24 Likes

Could you put the code in code blocks please so we could read it easier? Thank you.

What is the purpose of this?
It only resumes and then yields.

That’s what I mean I tried to do it but its kind of hard.

Tween the sound volume out after the gui is removed, but also use :Destroy() instead of :remove()

Parent the sound to workspace instead of the gui. And then destroy the sound after its done tweening.

Why not parent to CurrentCamera so only the client hears the music?

You can use a callback function in addition to @Halalaluyafail3’s code.

local Tween = TweenService:Create(sound,TweenInfo.new(1),{Volume = 0})
Tween:Play()
Tween.Completed:Connect(function(State)
	if State == Enum.PlaybackState.Completed then
		sound:Destroy()
		Tween:Destroy()
	end
end)
3 Likes

You can also use SoundService::PlayLocalSound.

1 Like
wait(24)

local text = "SWORD REALMS"

local player = script.Parent.Parent
local gui = script.Parent
local sound = Instance.new("Sound",gui)
sound.SoundId = ""
sound.Pitch = 1
sound.Volume = 0.8
local frame = gui.Frame
local text1 = frame.TextLab
wait(1)
sound:play()
for i = 1,string.len(text),1 do
	text1.Text = string.sub(text,1,i)
	wait(0.1)
end
coroutine.resume(coroutine.create(function()
	for i = 0, 0.8, 0.05 do
		sound.Volume = i
		wait(0.5)
	end
end))
for i = 1,50,1 do
	text1.TextTransparency = text1.TextTransparency + 0.02
	wait(0.01)
end
gui:Destroy()

The code that I would use would be:

-- Variables --

local Workspace = game:GetService("Workspace")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Title = "SWORD REALMS"
local GUI = script.Parent

local Sound = Instance.new("Sound")
Sound.Parent = Workspace
Sound.SoundId = ""
Sound.PlaybackSpeed = 1
Sound.Volume = 0.8

local Frame = GUI:WaitForChild("Frame")
local TextLabel = GUI:WaitForChild("TextLab")

-- Scripting --

wait(25)

Sound:Play()

for i = 1, Title:len(), 1 do
	TextLabel.Text = Title:sub(1, i)
	wait(0.1)
end

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

for i = 1, 0, 0.02 do
	TextLabel.Transparency = i
	wait(0.01)
end

Sound:Destroy()
GUI:Destroy()
1 Like

You can start playing the sound before the loop for the text effect. There is no reason to re-play it every time.