Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Disconnect is not a valid member of RBXScriptSignal?

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

0

Botted views

2 answers

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.

1 comment

0

a new song keeps playing on top of the first song

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

This discussion is preserved as it was. New answers, comments, and votes are closed.