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

How to make a sound increasingly louder after some time?

Asked by 4 years ago

Hi, I'm building a game where I have a "Heavy breathing" looped sound, but I also want it to get louder as time passes. I placed a normal script in a sound and put

local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://2613820616"
sound.Looped = true
sound.PlaybackSpeed = 1


sound.Volume = 0.3 --original volume

sound:Play() --plays the sound

wait(7)

sound.Volume = 1 --volume goes up

sound:Play() --plays

wait(12) --but after that is stops working from here?

sound.Volume = 4

sound:Play()

It works to make the volume go from 0.3 to 1, but it stops at that. Is there something I need to add? I got the script from here and just wanted to continue with the script to make it appear to increase in volume.

Any help is appreciated.

3 answers

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

Explanation

First of all, you don't need to place the script inside a sound, place it in the Workspace instead. The reason is that because the script creates the breathing sound and places it in the Workspace and that is because if you go to Line 01, you can clearly see that local sound = Instance.new("Sound", game.Workspace) is there and it creates another sound..

I've tested your script and it works completely fine, all you need do is place the script in the Workspace and you are good to go!

Solution

Now, I'll explain what the script does;

local sound = Instance.new("Sound", game.Workspace)  -- Creates a new sound in the workspace
sound.SoundId = "rbxassetid://2613820616"  -- This is the sound Id that will be played, you can change it's id to whatever sound you would like to play.
sound.Looped = true  -- Loops the sound so that it will play again when it ends
sound.PlaybackSpeed = 1 -- This should be always set to 1!

sound.Volume = 0.3 --Volume for the sound, you can increase it if you like..

sound:Play() --Plays the sound.

wait(7)  -- Waits 7 seconds before going through these next lines of code

sound.Volume = 1 -- Volume will be now set to 1 (Volume increases)

sound:Play() --Plays the sound

wait(12) -- Waits 12 seconds before going through these last 2 lines of code

sound.Volume = 4 -- Sets the volume to 4

sound:Play() -- Plays the sound

Make sure to up vote and select this as the answer if the script works and you've understood!

0
Oh my god thank you so much! Thanks for thoroughly explaining, it was easy to understand and I was able to build off with what you said. Thank you so much, I'd upvote but I don't have enough rep :( Thank you, I really appreciate it! Aprilsaurus 48 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Here is how I would accomplish this. I'll post some code and explain what it does.

local targetVolume = 4 -- set the highest it can go (max 10)
local interval = 3
local increment = 2

local sound = Instance.new("Sound")

coroutine.wrap(function()
    repeat
        wait(interval)
        sound.Volume = sound.Volume + 2
        interval = interval + 1
        increment = increment + 1
    until
        sound.Volume >= targetVolume
end)()  

so here I increase the sound by a growing rate, and increase a growing rate. It's put in a coroutine so it doesn't stop the script. Reply with more questions, and mark this answer as correct if it works!

0
I'm running the script right now, but could you kind of explain what each line does so I could maybe change some things? It seems to work but I would like to customize some things. Thanks for the help though! Aprilsaurus 48 — 4y
Log in to vote
0
Answered by 4 years ago

The way I think of to increase the sound throughout is using a for loop. Here:

local maxvolume= 9 --set this to whatever you like
local minimumvolume= 1 --same goes for line one
local sound= game.Workspace.Sound --Just an example of the pathway

for i= minimumvolume,maxvolume,1 do
 sound.Volume= i
wait(7)
end

So here, I set some variables to indicate the minimum and maximum volume. I also made a pathway to the sound object that the code is manipulating.

The for loop will keep increasing the volume up to a certain point. Pretty simple script that's easy to understand. s

0
Thank you for the help! But my question was already solved, thank you though! Aprilsaurus 48 — 4y

Answer this question