How to disconnect/stop InputBegan?

I’m trying to make it so that once the button is pressed, it “enables” the InputBegan function to check if the player clicked, if so then end the function. However, the function still fires and I’m confused why that is?

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local object = Player.PlayerGui.Build.BackFrame.MainFrame.BuildScroll.Armor1.Object

local button = object.Button.Activated:Connect(function()
    local click = UserInputService.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            print("Clicked")
        end
    end)
    local Update = RunService.RenderStepped:Connect(function()
    end)
    object.Button.Activated:Connect(function()
        Update:Disconnect()
    end)
end)
1 Like

If I’m understanding correctly, you want to disconnect the InputBegan event once the player clicks their mouse:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local object = Player.PlayerGui.Build.BackFrame.MainFrame.BuildScroll.Armor1.Object

local button ; button = object.Button.Activated:Connect(function()
	local click ; click = UserInputService.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			print("Clicked")
			click:Disconnect()
		end
	end)
	
	-- your other code
end)
3 Likes