GUI requires to click twice before disconnecting a function on start

Hi there, I have a script that executes function based on the mouse click and the problem is, is that it works but when joining a game it requires to be clicked twice to disconnect the function. I have the function connected on default. I’ve tried changing the “connected = not connected” and still couldn’t go anywhere.

local RunService = game:GetService("RunService")
local Button = script.Parent
local musicplayer = workspace.Sound
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
	CameraMinFOV = 70,
	CameraMaxFOV = 80,
	CameraMaxVolume = 1500
}

local connected = true

local function changeCameraShakeState()
	if not connected then
		game:GetService("RunService"):BindToRenderStep("CurrentTrack", 1, function()
			local CurrentLoudness = musicplayer.PlaybackLoudness
			local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
			if FOV > 0 and FOV < 130 then
				CurrentCamera.FieldOfView = FOV
			end
		end)
	else
		RunService:UnbindFromRenderStep("CurrentTrack")
	end
	connected = not connected
end

Button.MouseButton1Click:Connect(changeCameraShakeState)

have you tried this:
if connected then

instead of:

the problem is, is that the function is connected when a player joins the game

disconnected* sorry autocorrect

try putting the connected = not connected at the top of the function instead of the bottom.

local function changeCameraShakeState()
connected = not connected -- Put it here
	if not connected then
		game:GetService("RunService"):BindToRenderStep("CurrentTrack", 1, function()
			local CurrentLoudness = musicplayer.PlaybackLoudness
			local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
			if FOV > 0 and FOV < 130 then
				CurrentCamera.FieldOfView = FOV
			end
		end)
	else
		RunService:UnbindFromRenderStep("CurrentTrack")
	end
-- Instead of here
end

its still disconnected and also requires to be click twice to connect