Keybind system: MouseButton1Down isn't running after textbutton clone

Yeah, I apologize for posting here so consistently. Still learning.
So basically, with my code it creates a button and when it clicks it it waits for the player to press a key and then changes the keybinds value with it. (I run that on the client just for testing)

Now so, when I run this. No errors. 1 and 2 prints. The print(a.ClassName, a.Name) prints correctly but I don’t get that print('ok') after the mousebutton1down event. The ClassName prints as a textbutton.

I’ve attempted to debug, changing things around for like 20 minutes but I can’t seem to get this to work.
Any help would be great, thanks.

p.s: (sorry)

Code:


for bindName, bindSettings in next, Keybind_Module do
	print(1)
	if bindSettings.Active == true and bindSettings.Editable == true then
		print(2)
		local a = TemplateBind:Clone()
		a.Name = bindName
		a.Text = bindName.." Bind: "..bindSettings.DefaultBind
		a.Parent = keybindFrame.Binds
		a.Visible = true
		
		local conn 
		print(a.ClassName, a.Name)
		a.MouseButton1Down:Connect(function()
			print('ok')
			a.Text = "Set new bind"
			conn = UserInputService.InputBegan:Connect(function(object, g)
				if not g then
					local key = object.KeyCode
					keybinds[a.Name].Value = key
					
					a.Text = "Bind: "..key
					conn:Disconnect()
				end
			end)
			
		end)
	end
end
1 Like

My fear is that you’re clicking on something else, or that you’re clicking on something above it

On a side note, here’s a different way to organize your button1down connection (no need for conn

a.MouseButton1Down:Connect(function()
	print('ok')
	a.Text = "Set new bind"

	local object, g = UserInputService.InputBegan:Wait()

	if not g then
	     local key = object.KeyCode
	     keybinds[a.Name].Value = key
	     
	     a.Text = "Bind: "..key
	end
end)
4 Likes

Thank you. I’ve edited my code for that.

The MouseButton1Down thing is really weird because I’m clearly clicking it.

Seemed to fix it by instead of cloning the main frame when I want to open it, I have it already out but invisible.

1 Like