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

How Do I Make Music Fade In On My Game?

Asked by 5 years ago

i want to use a script to fade the music in and out but adding small amount of volume to make it seem like its fading in doesn't seem to work?, anyone able to help me out Thanks! ```i = 15 -- intermission timesssssssssssssssssssssssssss music:Play() partyf.Enabled = true partys.Enabled = true partyf2.Enabled = true partys2.Enabled = true partyf3.Enabled = true partys3.Enabled = true while i>= 0 do stat.Value = ('Game Begining in ' .. i) wait(1.15) -- timer i = i -1 end

0
This is what i have so far Odlnsonthor 11 — 5y

2 answers

Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
5 years ago

This can be accomplished by a simple for loop.

Wiki definition: A loop is a chunk of code that is executed multiple times. There are three types of loops: for, while, and repeat. Each type loops a block of code, but in different ways.

For this example, we will be using the for loop.

Since you want the volume to fade in, we'll want the for loop to be increasing.

There are 3 values needed here, your starting point, end point, and how much you wish to increase/decrease the starting point by, within a specific time frame.

for i = 0, 0.5, 0.1 do

This essentially means that i is equal to 0, and it wants to be equal to 0.5 (the default volume of a Roblox sound instance), and that it wishes to increase by an increment of 0.1.

Now, the code inside of this loop will repeat until the end point has been reached, and it will then break.

So we should set the volume of the sound equal to the value of i.

music.Volume = i

Now, we have a minor problem, this code will run too fast for anybody to even notice, and this is because there is no delay between each loop, meaning that it thinks we want it to just run the code as fast as possible, however this is not the case.

We can fix this by adding a wait() and setting a value for how long we wish to wit between each loop, after we set the volume to i.

wait(0.1)

This means that every 0.1 seconds, the volume will increase by 0.1 until it reaches 0.5, at which point the loop will break.

Now, you can mess with these values a little yourself, to find a fade that you think fits your needs.

You can read more on basic loops here.

Full code:

for i = 0, 0.5, 0.1 do
    music.Volume = i    
    wait(0.1)
end

If you have any queries or concerns, then leave a comment and I'll get back to you as soon as possible.

Happy scripting!

0
would i play music outside loop then the loop follows? Odlnsonthor 11 — 5y
0
Yes, play the music outside of the loop. awfulszn 394 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Just make a for loop that decreases the volume gradually.

0
it didnt work earlier when i tried Odlnsonthor 11 — 5y
0
Are you using waitforchild()? ClockWallie 28 — 5y
0
yes i was Odlnsonthor 11 — 5y
0
try making a infinite loop to check it ClockWallie 28 — 5y

Answer this question