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.