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

2 comments
Usually in cases like yours I try putting
printstatements 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 runninghow would i disconnect it?