I have this script that plays a playlist which also has a fov script with it too, but I'm trying to disconnect the function inside of the loop after the song has ended? Please tell me whats wrong, and try to explain since I'm quite new to Lua.
while true do
local randomTrack = availableMusic[math.random(1,#availableMusic)]
local connection = game:GetService("RunService").RenderStepped
currentTrack.Value = "..." -- displays the song playing in a music player gui
wait(2)
randomTrack:Play()
local ScreenShakeSettings = {
CameraMinFOV = 70,
CameraMaxFOV = 80,
CameraMaxVolume = 1500
}
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()
connection:disconnect(function()
end)
end

1 comment
Botted views