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

Disconnect is not a valid member of RBXScriptSignal?

Asked by
vxsqi 5
3 years ago

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
0
Botted views WishXVI 94 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
local connection

connection = game:GetService("RunService").RenderStepped:connect(function()
--Insert FOV code
end)

randomTrack.Ended:Wait()

connection:Disconnect()

You have to state that connection is the RenderStepped event before disconnecting it.

0
a new song keeps playing on top of the first song vxsqi 5 — 3y
Ad
Log in to vote
0
Answered by
vxsqi 5
3 years ago

I tried this and a new song kept playing

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
    }
local connection
    connection = game:GetService("RunService").RenderStepped:connect(function()
        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()

    end)
end

Answer this question