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

PlaybackLoudness script not looping after the next song plays?

Asked by
vxsqi 5
2 years ago
Edited 2 years ago

Hello, I have this script where it changes the fov based on PlaybackLoudness but it only works once and stops working after the next song plays. Ignore line 3 as thats for displaying the current song in a music player I have.

local randomTrack = availableMusic[math.random(1,#availableMusic)]

    currentTrack.Value = "..."

    wait(2)

    randomTrack:Play()

    local ScreenShakeSettings = {
        CameraMinFOV = 70,
        CameraMaxFOV = 90,
        CameraMaxVolume = 1200
    }


    game:GetService("RunService").RenderStepped:connect(function()
        local CurrentLoudness = randomTrack.PlaybackLoudness
        local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
        if FOV > 0 and FOV < 130 then
            CurrentCamera.FieldOfView = FOV
        end
    end)

    currentTrack.Value = randomTrack.Name 

    randomTrack.Ended:Wait() 

end
0
Usually in cases like yours I try putting `print` statements in various places to try and figure out what's running and confirm the values of variables are what I expect. Unrelated, since this is run more than once, you should be sure to disconnect the connection made (from line 16) when you're done with it (when the song ends, line 27) or else you'll end up with tons of connections always running chess123mate 5873 — 2y
0
how would i disconnect it? vxsqi 5 — 2y

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago

It's because you did not update the randomTrack value inside the function. That's why when the song ends, the function detects nothing from the song, but another song is still playing. You could try updating the randomTrack value inside the function.

0
Forgot to mention, above line 1 is actually a “while true do”. I just didn’t include it in when posting this topic. If that’s not what you meant, how do I achieve this? vxsqi 5 — 2y
Ad

Answer this question