A weird bug, hard to explain

Hello, i have this script that detects if theres any input and if the button is pressed. It works works the button is pressed. But if you press a mouse button and its not pressing the button, the entire script just messes up, I want it to detect if theres input but only with the button

UserInputService.InputBegan:Connect(function(input, Typing)
	if Typing then return end
	
		if script.Parent.ImageButton.IfEquiped.Value == true then 
			
				player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip.MouseButton1Click:Connect(function()
				if AbilityReady == false then

					script.Parent.ClapSound:FireServer(Character)
					script.Parent.HandSignSound:FireServer(Character)


					player.PlayerGui.Ability.Frame:FindFirstChild("Name").Text = script.Parent.Name
					player.PlayerGui.Ability.Frame.Description.Text = script.Parent.ImageButton.Description.Value
					player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value].Visible = true
					print("Ablitiy ready for activation")
					AbilityReady = true
					ReadyAnim:Play()
					player.PlayerGui.Ability.Frame:TweenPosition(
						UDim2.new(0.313, 0, 0.83, 0),
						"In",
						"Linear",
						0.1,
						false

					)
					wait(0.1)
					script.Parent.SetImage:FireServer(Character)

				elseif AbilityReady == true then

					script.Parent.RemoveImage:FireServer(Character)
					AbilityReady = false
					script.Parent.Blue:FireServer(Character)
					print("Ablitiy not ready for activation")
					player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value].Visible = false
					ReadyAnim:Stop()
					TigerAnim:Stop()
					RamAnim:Stop()
					SnakeAnim:Stop()
					MonkeyAnim:Stop()
					BoarAnim:Stop()
					HorseAnim:Stop()
					BirdAnim:Stop()
					OxAnim:Stop()
					RatAnim:Stop()
					hareAnim:Stop()
					DogAnim:Stop()
					DragonAnim:Stop()
					state = 0
					for i,v in pairs(player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value]:GetChildren()) do
						v.TextColor3 = Color3.new(0, 0, 0)
					end
					player.PlayerGui.Ability.Frame:TweenPosition(
						UDim2.new(0.313, 0, 1, 0),
						"In",
						"Linear",
						0.1,
						false
					)
				end
			end)
			end
			
	
	
end)

just ignore all that extra stuff, thats the stuff that gets messed up

you mean

TextButton.MouseButton1Down:Connect(function()
    --whatever
end)

?

Will this solve the problem? if so, can you please explain to me the difference between that and MouseButton1Click

No, no, I mean that you don’t need the input began, do you? You can simply use the MouseButton1Click or the MouseButton1Down.

Oh no, i need the input began. So when it detects input it checks if the value is equal to true, The second function with the MouseButton1Click wont work if the value is equal to true, so i need it to detect each time to determine

so you mean this:

player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip.MouseButton1Click:Connect(function()
	if not script.Parent.ImageButton.IfEquiped.Value then return end
	--code
end)

no checking the value has to come first, because if the value isnt equal to true, i dont want it to let them press the button

That’s exactly what that does, if the value is false, the code doesn’t continue.

If the value is equal to false, they cant even press the button at all, thats what i want. You did it the other way around

They can click the button either way. You never disabled the button in any way. There is no way to completely disable a button as far as I know. Also, your code continues to stack click events on top of each other, causing problems.

In my script, i said if the value is equal to true, then they can press the button. And if its not, they cant. So is there another solution or…?

I believe you can set the active value to false.

local Equipped = script.Parent.ImageButton.IfEquiped
local Button = player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip

Equipped:GetPropertyChangedSignal("Value"):Connect(function()
	Button.Active = not Equipped.Value
end)

Button.Activated:Connect(function()
	--code
end)

Activated can only run if Active is true.

Does the same exact thing it does before, if the player presses anywhere else then presses the button, it bugs out

Maybe, we could switch to something completely different that ca save it. Any way to see if the mouse position is over the button as an if statement?

Again, don’t use the input began at all.

Ok, then tell me how it would know each time to check if its equal to true to let them press the button?

Simply this:

local Equipped = script.Parent.ImageButton.IfEquiped
local Button = player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip

Equipped:GetPropertyChangedSignal("Value"):Connect(function()
	Button.Active = not Equipped.Value
end)

Button.Activated:Connect(function()
	if AbilityReady == false then

		script.Parent.ClapSound:FireServer(Character)
		script.Parent.HandSignSound:FireServer(Character)

		player.PlayerGui.Ability.Frame:FindFirstChild("Name").Text = script.Parent.Name
		player.PlayerGui.Ability.Frame.Description.Text = script.Parent.ImageButton.Description.Value
					player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value].Visible = true
		print("Ablitiy ready for activation")
		AbilityReady = true
		ReadyAnim:Play()
		player.PlayerGui.Ability.Frame:TweenPosition(
			UDim2.new(0.313, 0, 0.83, 0),
			"In",
			"Linear",
			0.1,
			false

		)
		wait(0.1)
		script.Parent.SetImage:FireServer(Character)

	elseif AbilityReady == true then

		script.Parent.RemoveImage:FireServer(Character)
		AbilityReady = false
		script.Parent.Blue:FireServer(Character)
		print("Ablitiy not ready for activation")
		player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value].Visible = false
		ReadyAnim:Stop()
		TigerAnim:Stop()
		RamAnim:Stop()
		SnakeAnim:Stop()
		MonkeyAnim:Stop()
		BoarAnim:Stop()
		HorseAnim:Stop()
		BirdAnim:Stop()
		OxAnim:Stop()
		RatAnim:Stop()
		hareAnim:Stop()
		DogAnim:Stop()
		DragonAnim:Stop()
		state = 0
		for i,v in pairs(player.PlayerGui.Ability.Frame[script.Parent.ImageButton.LeftClick.Value]:GetChildren()) do
			v.TextColor3 = Color3.new(0, 0, 0)
		end
		player.PlayerGui.Ability.Frame:TweenPosition(
			UDim2.new(0.313, 0, 1, 0),
			"In",
			"Linear",
				0.1,
			false
		)
	end
end)

Yeah, this isnt going anywhere, thanks for trying to help though