MouseButton1Click is not a valid member when connecting and disconnecting a function on GUI

Hi there, I have a fov script that connects and disconnects a function which is the screen shake when clicked, but I get the error "MouseButton1Click is not a valid member of TextLabel “Players.vxsqi.PlayerGui.Toggle Screen Shake.TextLabel”. I don’t understand what to attempt in order to fix this since the locals are fine and normal.

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 = false

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)

GuiButton.MouseButton1Click is an event only available to instances that inherit GuiButton–such as TextButton.

  1. TextLabel inherits GuiObject so consider trying GuiObject.InputBegan
  2. Change your TextLabel into a TextButton.

You can use this plugin to change the ClassName without re-creating it. Not necessary but it saves time

I can’t believe I was so stupid and forgot about this, thank you!