MouseButton1Click event not firing

I’m creating a building system in my game. Previously, the script that handled car creation worked perfectly fine, but now, the MouseButton1Click event is not firing for some reason.
And In case you were wondering, yes they are all text buttons, and yes they are all printed.

button.MouseButton1Click:Connect(function()
	disableConnections()

	local inventoryFrame = script.Parent.Parent.InventoryFrame

	inventoryFrame.Visible = true
	inventoryFrame.Inventory.Text = "Choose a part"

	destroy.Visible = false
	button.Visible = false

	returnButton.Visible = false
	for _, invItem in inventoryFrame.ScrollingFrame:GetChildren() do

		if invItem:IsA("TextButton") then
			print(invItem)
			invItem.MouseButton1Click:Connect(function()
				print("event")
				inventoryFrame.Visible = false

				destroy.Visible = true
				button.Visible = true

				returnButton.Visible = true

				local id = invItem:GetAttribute("Id")
				local class = invItem:GetAttribute("Class")

				placePart(id, class)

			end)
		else
			print("a")
		end
	end
end)

Try to put many print() in the script and check where it stops and maybe because the button has the property Active set to false or something happens in the disableConnections() function

FYI, print("event") doesn’t fire, but print(invItem) does. Also the button has Active set to true.

This is weird: I put a local script inside of the button, and that event fires perfectly fine.

Did you use server script for GUI type button? This will result in the function working for everyone or possibly not working at all. Maybe I dont understand something or there isnt enough information.

If you’re talking about the script with the MouseButton1Click event in it, it’s a local script.

It stops at " event " since another function of Mouse1ClickButton is inside and before that run or read the first Mouse1ClickButton function must be clicked first before the one inside and to print the " event " the button must be clicked first then run the invItem and must be clicked to run the code inside it.

I think we could help u more if u provide more information about the outcome u desire.

2 Likes

When the button is clicked, it opens the inventoryFrame, which contains the user’s items, each of which are represented by a TextButton (quantity is accounted for). When the user clicks one of the TextButtons in InventoryFrame, PlacePart()should fire, and the Gui should revert.

does it has error msg in the output? If not try checking the UI zindex or if it’s interactable since it doesn’t fire when click maybe it can’t be click at the first place

There is nothing in the console.

There are a many reasons this might not be working, but it’s not because MouseButton1Click is broken. Usually, the button or its parent isn’t visible, or something else is covering it. Sometimes the button is offscreen or has zero size, so clicks don’t register. It can also happen if the event gets connected multiple times without disconnecting old connections. If the button gets replaced or recreated without reconnecting the event, it won’t fire. Checking these things will usually find the problem.

Check ZIndex order, input transparency, if any frames overlap the button, if the button or its parents are disabled or invisible, and the button’s size and position.

One odd one that can do this is AutoButtonColor = false and BackgroundTransparency = 1
The button can become unclickable because it’s fully transparent and not detecting input.

Also MouseButton1Click is only for local scripts.