Gui Button in Plugin doesn't fire

I’m trying to make a button for my plugin that when clicked on changes the color of the UI in the plugin but when I do:

button.MouseButton1Click:Connect(function()
  print("clicked")
end)

then click the button, nothing happens, yet everything else (even the two print statements before and after it) work. I can’t seem to figure out why it won’t work; it’s parented to the correct place, when I hover and click on it it changes color because of the autocolor property, I’ve checked the spelling 40 times over, but yet still don’t know where the problem is.

Entirity of the Code:
local SettingsFrame = script.Parent:WaitForChild("Frame")

local Colors = {}

function Colors.new(menu, tabs)
    -- menu is the main UI of the plugin that the SettingsFrame 
    -- is parented to, it's just needed to change the color of the menu
    -- tabs is also a similar situation where I only include it to change the color.
	local self = setmetatable({}, {__index = Colors})
	
	self.ColorList = {}
	self.SelectedColor = nil
	self.Menu = menu
	self.Tabs = tabs
	
	return self
end

function Colors:AddColor(name, shade1, shade2, shade3, shade4)
	table.insert(self.ColorList, {
		Name = name,
		ShadeA = shade1,
		ShadeB = shade2,
		ShadeC = shade3,
		ShadeD = shade4,
		Button = Colors:CreateButton(shade1, shade2, shade3, #self.ColorList + 1)
	})
end

function Colors:CreateButton(shade1, shade2, shade3, index)
	local button = Instance.new("TextButton")
	button.AutoButtonColor = true
	button.Active = true
	button.Size = UDim2.new(.9, 0, .9, 0)
	button.SizeConstraint = Enum.SizeConstraint.RelativeYY
	button.Text = ""
	button.ZIndex = 5
	
	local corner = Instance.new("UICorner")
	corner.CornerRadius = UDim.new(1, 0)
	
	local stroke = Instance.new("UIStroke")
	stroke.Color = Color3.new(1, 1, 1)
	stroke.Thickness = 2
	stroke.Enabled = false
	
	stroke.Parent = button
	
	local shade2Inst = Instance.new("Frame")
	shade2Inst.AnchorPoint = Vector2.new(.5, .5)
	shade2Inst.Position = UDim2.new(.5, 0 ,.5, 0)
	shade2Inst.ZIndex = 5
	
	local shade3Inst = shade2Inst:Clone()
	
	button.BackgroundColor3 = shade1
	corner.Parent = button
	shade2Inst.Size = UDim2.new(.7, 0, .7, 0)
	shade2Inst.BackgroundColor3 = shade2
	corner:Clone().Parent = shade2Inst
	shade3Inst.Size = UDim2.new(.5, 0, .5, 0)
	shade3Inst.BackgroundColor3 = shade3
	corner:Clone().Parent = shade3Inst
	
	shade3Inst.Parent = shade2Inst
	shade2Inst.Parent = button
	button.Parent = SettingsFrame.ColorSelection
	
	print("connected") -- works
	button.MouseEnter:Connect(function()
		print("entered") -- doesn't work
	end)
	--Here's the Problem--------------------------------------
	button.MouseButton1Click:Connect(function()
		print("clicked") -- doesn't work
		self:SetColors(index)
	end)
	print("returning value") -- works
	return button
end

function Colors:SetColors(index)
	if self.SelectedColor ~= index then
		self.ColorList[self.SelectedColor].Button.UIStroke.Enabled = false
		
		local color = self.ColorList[index]
		color.Button.UIStroke.Enabled = true
		
		self.Tabs:ChangeColor(color.ShadeA, color.ShadeB, color.ShadeC, color.ShadeD)
		self.Menu.BackgroundColor3 = color.ShadeA
		self.Menu.TitleBox.BackgroundColor3 = color.ShadeB
		self.Menu.TitleBox.LevelCreator2D.TextColor3 = color.ShadeC
	end
end

return Colors

I just want the print statements in the events to work. Not concerned with the rest of the code working right now.

I don’t think you can put event inside function try to make the event after the functio

Could you elaborate? do you mean the Colors:SetColors(index) or the event?

The event "mouse.button1clicked " s

1 Like

Nope, didn’t work. Though I kinda already knew that since I wrote this code thats conditioned similarly and it works as planned.

function Tabs:CreateTab(imageID, index)
	local tab = script.Tab:Clone()
	tab.ImageLabel.Image = imageID
	tab.Parent = self.Scroll
	
	tab.MouseButton1Click:Connect(function()
		self:Set(true, index)
	end)
	
	return tab
end

So try to Change Variable name from button ?

1 Like

I tried renaming “button” to “changeColorButton” but it didn’t work.

If you delete mouse enter event does it work ?

1 Like

no, mouseenter doesn’t have any effect on the mouseclick event. I originally added it because I was checking if the button took any input at all, but it wasn’t working before that either.

How about MouseButton1Up?

(chat limit jjjjj)

1 Like

Nope, doesn’t work. Though I believe I have an idea what might be causing it.

I figured it out. I was creating the buttons and connecting them to the frame BEFORE cloning the frame. I had to do it after because the connections apparently don’t get cloned. thx for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.