MouseButton1Click not really working?

Here’s my code:

for _, Table in pairs(scriptsHolder) do
	local Dropdown = ScriptList:FindFirstChild(Table.Category)
	
	if not ScriptList:FindFirstChild(Table.Category) then
		local Category = Instance.new("Frame")
		local CategoryName = Instance.new("TextLabel")
		local DropdownArrow = Instance.new("TextLabel")
		local DropdownButton = Instance.new("TextButton")
		local Container = Instance.new("Frame")
		local List = Instance.new("UIListLayout")

		Category.Name = Table.Category
		Category.Parent = ScriptList
		Category.AnchorPoint = Vector2.new(0.5, 0.5)
		Category.BackgroundTransparency = 1
		Category.BorderSizePixel = 0
		Category.Size = UDim2.new(1, 0, 0, 19)

		CategoryName.Name = "CategoryName"
		CategoryName.Parent = Category
		CategoryName.AnchorPoint = Vector2.new(1, 0)
		CategoryName.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
		CategoryName.BackgroundTransparency = 1.000
		CategoryName.Position = UDim2.new(1, 0, 0, 0)
		CategoryName.Size = UDim2.new(1, -5, 0, 19)
		CategoryName.Font = Enum.Font.SourceSans
		CategoryName.Text = Table.Category
		CategoryName.TextColor3 = Color3.fromRGB(255, 255, 255)
		CategoryName.TextSize = 14.000
		CategoryName.TextWrapped = true
		CategoryName.TextXAlignment = Enum.TextXAlignment.Left
		CategoryName.ZIndex = 2

		DropdownArrow.Name = "DropdownArrow"
		DropdownArrow.Parent = Category
		DropdownArrow.AnchorPoint = Vector2.new(1, 0)
		DropdownArrow.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
		DropdownArrow.BackgroundTransparency = 1.000
		DropdownArrow.Position = UDim2.new(1, -5, 0, 2)
		DropdownArrow.Rotation = -90
		DropdownArrow.Size = UDim2.new(0, 15, 0, 15)
		DropdownArrow.Font = Enum.Font.SourceSansBold
		DropdownArrow.Text = "<"
		DropdownArrow.TextColor3 = Color3.fromRGB(255, 255, 255)
		DropdownArrow.TextSize = 14.000
		DropdownArrow.ZIndex = 2

		DropdownButton.Name = "DropdownButton"
		DropdownButton.Parent = Category
		DropdownButton.AnchorPoint = Vector2.new(0.5, 0)
		DropdownButton.AutoButtonColor = false
		DropdownButton.BackgroundColor3 = Color3.fromRGB(39, 39, 39)
		DropdownButton.BackgroundTransparency = 0
		DropdownButton.BorderSizePixel = 0
		DropdownButton.Position = UDim2.new(0.5, 0, 0, 0)
		DropdownButton.Size = UDim2.new(1, 0, 0, 19)
		DropdownButton.Font = Enum.Font.SourceSans
		DropdownButton.Text = ""
		DropdownButton.TextColor3 = Color3.fromRGB(0, 0, 0)
		DropdownButton.TextSize = 14.000
		
		Container.Name = "Container"
		Container.Parent = Category
		Container.AnchorPoint = Vector2.new(0.5, 0)
		Container.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
		Container.BackgroundTransparency = 1
		Container.Position = UDim2.new(0.5, 0, 0, 19)
		Container.Size = UDim2.new(0, 100, 0, 0)
		
		List.Name = "List"
		List.Parent = Container
		List.SortOrder = Enum.SortOrder.LayoutOrder
		
		Dropdown = Category
		
		DropdownButton.MouseButton1Click:Connect(function()
			if DropdownArrow.Rotation == 180 then
				DropdownArrow.Rotation = -90
				Dropdown.Size = UDim2.new(1, 0, 0, (#Container:GetChildren() * 17) + 5)
				Container.Visible = true
			else
				DropdownArrow.Rotation = 180
				Dropdown.Size = UDim2.new(1, 0, 0, 19)
				Container.Visible = false
			end
		end)
	end
	
	local Container = Dropdown:FindFirstChild("Container")
	
	local Script = Instance.new("TextButton")
	local ScriptName = Instance.new("TextLabel")

	Script.Name = Table.Name
	Script.Parent = Container
	Script.AnchorPoint = Vector2.new(0.5, 0.5)
	Script.Active = true
	Script.BackgroundColor3 = Color3.fromRGB(75, 75, 75)
	Script.BackgroundTransparency = 1.000
	Script.BorderSizePixel = 0
	Script.Position = UDim2.new(0.401606441, 0, 0.0799999982, 0)
	Script.Size = UDim2.new(1, 0, 0, 17)
	Script.AutoButtonColor = false
	Script.Font = Enum.Font.SourceSans
	Script.Text = ""
	Script.TextColor3 = Color3.fromRGB(255, 255, 255)
	Script.TextScaled = true
	Script.TextSize = 14.000
	Script.TextWrapped = true

	ScriptName.Name = "ScriptName"
	ScriptName.Parent = Script
	ScriptName.AnchorPoint = Vector2.new(1, 0.5)
	ScriptName.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	ScriptName.BackgroundTransparency = 1.000
	ScriptName.Position = UDim2.new(1, 0, 0.5, 0)
	ScriptName.Size = UDim2.new(1, -5, 1, 0)
	ScriptName.Font = Enum.Font.SourceSans
	ScriptName.Text = Table.Name
	ScriptName.TextColor3 = Color3.fromRGB(255, 255, 255)
	ScriptName.TextSize = 13.000
	ScriptName.TextWrapped = true
	ScriptName.TextXAlignment = Enum.TextXAlignment.Left
	
	Dropdown.Size = UDim2.new(1, 0, 0, (#Container:GetChildren() * 17) + 5)
	
	Script.MouseButton1Click:Connect(function()
		print("t")
	end)
end

Only 2/4 buttons actually work but after clicking one for a long time it then works for a little bit until you click on a different one, then it breaks again

1 Like

I prefer to use ‘Activated’ Event cause the event can also be used in mobile games.

1 Like

I replaces MouseButton1Click with Activated but it still refuses to work, any other ideas?

If you are trying to listen a button event from the server side?

No, from a local script so client sided

Are you getting any errors in the console? Or is there anything else that would be useful info

No errors in console, nothing comes off as weird when using breakpoints, I’m super confused as to why it only sometimes works. I even went as far as messing with ZIndexs.

1 Like

Maybe it’d be efficient to have a wait() / task.wait() in the script. But other than that I think you should test in-game to check console for errors, as that would probably be more precise.

still isn’t working, again nothing in console

I see script and dropdownbutton as mouseclick functions, what are the other two?

may you try to make new buttons and test on mouseButton1Click event in another place? I have tried it once and it works well.


The problem seems like a scripting issue. I am not sure whether you have placed two buttons in the same position on screen. Or you can try to disconnect the connection of button event at proper timing.

Explorer:
image

Gui:
image

I created using one script and checked for mouse clicks on another and it still does the exact same thing.
I have found out though that when I hold the button down for a bit then let go it selects it now matter what but simple clicks only work for the top “Test” of each category.

Scratch that, it only detects clicks outside the TextLabel boundaries even when it isn’t created
image
(light gray represents it bit being clicked)

image
(the blue box is the text label boundaries, i have to click in the tiny spot over to the left)

So, basically, the TextLabel is infront of the TextButton preventing it from being clicked. Gladly, we have the ZIndex property, the higher it is the more “layers above” it shows, so try putting the button’s ZIndex bigger than the TextLabel.

I’ve already tried this, even going as far as setting the ZIndex of the button to 100. It still refuses to work. I don’t know if it’s relevant but i forgot to mention that List frame is actually a ScollingFrame.

And again to re-iterate, the first button in each category work perfectly fine, it’s only the rest of the buttons.

Why you saying Script.MouseButton1Click? Try script.Parent.MouseButton1Click Or is Script a Variable?

Script is a variable, but I fixed my own problem. Another ScreenGui that was disabled had a frame that was not visible but overlapped in that small area, and for some reason it was blocking the specific are of buttons.

1 Like