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

Entering building makes music fade in fine but exiting it makes it instantly silence?

Asked by 4 years ago
Edited 4 years ago

So basically, I am trying to make sure that this script slowly turns music up and the background rain down when a player enters the building. There is another block that the player hits which should slowly turn the music down and the rain back up. Instead it prints the "test" print over 400 times and instantly silences the music, and then instantly makes the rain shoot up to full volume. One would assume it has to do with debounce, but with and without, it still does this. Any ideas?

local s1 = workspace.Rain
local d = workspace.Jazz
local r = workspace.RainDoor

local bgm = workspace:WaitForChild("Music")

local music = bgm:GetChildren()

local debounce = false
local raindebounce = false

s1:Play()

d.Touched:Connect(function()
    if raindebounce == false and s1.Volume >= 5 then
        for i = 1,10 do
            s1.Volume = s1.Volume - 0.4
            raindebounce = true
            wait(0.1)
        end
        raindebounce = false
    end
    if debounce == false then
        while true do
            debounce = true
            local randomsong = math.random(1, #music)
            randomsongplay = music[randomsong]
            randomsongplay:Play()
            for i = 1,100 do
                randomsongplay.Volume = randomsongplay.Volume + 0.01
                wait(0.01)
            end
            wait(randomsongplay.TimeLength)
            for i = 1,100 do
                randomsongplay.Volume = randomsongplay.Volume - 0.01
                wait(0.01)
            end
            randomsongplay:Stop()
            wait()
        end
    end
end)
r.Touched:Connect(function()
    local exitdebounce = false
    if exitdebounce == false then
        exitdebounce = true
        for i = 1,10 do
            print'test'
            randomsongplay.Volume = randomsongplay.Volume - 0.1
            debounce = true
            wait(0.1)
        end
        for i = 1,10 do
            s1.Volume = s1.Volume + 0.4
            raindebounce = true
            wait(0.1)
        end
        exitdebounce = false
    end
end)
wait()

Any and all help will be greatly appreciated!

Answer this question