MouseButton1Click & MouseButton1Down not working

Hello!

I’ve been making placement system GUI but somehow, MouseButton1Click doesn’t working.
Here’s my code:

--

local BuildButtonConnection = {}

for i,v in pairs(game.ReplicatedStorage.Objects:GetChildren()) do
				if v.ClassName == "Model" then
					local NewObject = BuildObjTemplate:Clone()
					local ItemClone = v:Clone()
					NewObject.Parent = CurrentFrameTarget
					NewObject.Name = v.Name
					NewObject.Visible = true
					NewObject.ObjectName.Text = v.Name
					local TextSize = TextService:GetTextSize(v.Name, 20, Enum.Font.GothamBold, Vector2.new(NewObject.AbsoluteSize.X, 40))
					NewObject.ObjectName.Size = UDim2.new(1,0,0,TextSize.Y)
					
					--

					BuildButtonConnection[NewObject] = NewObject.Select.MouseButton1Click:Connect(function()
						SelectedObjectName = v.Name
					end)
				end
				wait(0.15)
			end

--

This script worked when I replaced MouseButton1Click to InputBegan.
What’s wrong with it? Thanks for advance!

Here is object seen from explorer. (also, this is object BuildObjTemplate)
image

Try

function c()
	--do something
end


script.Parent.MouseButton1Down:connect(c)
1 Like

I made them to

local function c()
	SelectedObjectName = v.Name
end

BuildButtonConnection[NewObject] = NewObject.Select.MouseButton1Down:Connect(c)

still not working.

Are you putting the script inside a text button/image button?

No, it’s from different frame.
(also, my gui worked with no error.)
image

K well idk what else to do… sorry i couldn’t help :frowning:

1 Like

By “script” do you mean a server sided script or a local script?
Input functions will not work in a server script.

local script of course.


It’s probably an issue with your explorer hierarchy. I would check to make sure no gui objects are overlapping. Is there any chance that the function grabbed the wrong object? You could also chuck a print before and after the function.

Is there any chance that the function grabbed the wrong object?

No, as I said it in first, I changed MouseButton1Down to InputBegan and looks like it’s worked with no errors.

I would check to make sure no gui objects are overlapping.

The button has most highest ZIndex (GUIIndex is set to Sibling), so it’s on highest and not overlapped by anything, I guess.

Mess with the Active and Modal properties think they might have something to do with it. There’s also a chance something with a higher zindex that was active enabled is above it

1 Like

Yeah, ^^ Just looked at OP’s place. It turns out the build button had a higher z-index than the rest of the buttons/was covering them so they were unclickable.

2 Likes

Looks like I haven’t checked to GUI’s parent. (I was confused because AutoButtonColor was working.) Thank you for helping!