MouseButton1Click doesn't work

So I was making a custom NPC interaction system, and it wouldn’t work. A snippet of the script is as follows:

local button1 = script.Parent.TextButton1
button1.MouseButton1Click:Connect(function()
	print("e")
	if onchatlength == 0 then
		_storyline = "Coffee please"
		onchatlength = onchatlength + 1
	end
end)

When I click the button, it doesn’t print “e”. This is in a local script, located in the screenGUI, which is in the starter GUI. Why is this happening?

2 Likes

I think it’s MouseButton1Down, not MouseButton1Click.

Oops, I forgot about that. I just tried it with using MouseButton1Down, however it still doesn’t work…

Screen Shot 2021-06-10 at 10.34.25 AM
Also here’s the hierarchy

Try button1.Activated :grinning_face_with_smiling_eyes:

make sure the button isn’t covered by any kind of ui!

Still doesn’t work… (30 ch ars)

How would I make the button go to the top layer?

Trying printing onchatlength to make sure it == 0.

There should be an option called ZIndex on the button, set that to bigger than anything overlapping it. If you don’t know what to set it to, just do like 5.

1 Like

Very odd, MouseButton1Click has worked for me and that script should work.
try messing around with the actual properties of the text button maybe there’s a property that is disabling it.

also make sure there isn’t anything covering the button.

That’s wearied its not working for you, I just tried it with the exact same script. Herse what I got and the output is saying e

local button1 = script.Parent.TextButton1
-- Sometimes separating lines help. ( For me at least )
button1.MouseButton1Click:Connect(function()
  print("e")
  if onchatlength == 0 then
	_storyline = "Coffee please"
	onchatlength = onchatlength + 1
 end
end)

Are there any properties that can stop clicks from being detected?

I tried changing my zindex to 100, no luck

Not that I know of, heres mine

Actually, just moving the events to the very beginning of the script fixed it