This is a very interesting problem cause the problem line isn't working and it doesn't give a error it automatically changes the color and the selected object value isn't even the button. I would appreciate any help.
local selected = script.Parent.Parent.selected.Value
local basecolor = Color3.fromRGB(177, 177, 177)
if script.Parent.name.MouseButton1Click and selected == nil then -- the problem is this if and then
wait()
selected = script.Parent
selected.BackgroundColor3 = Color3.fromRGB(177, 177, 233)
else
selected.BackgroundColor3 = basecolor
wait()
selected = nil
selected.BackgroundColor3 = Color3.fromRGB(177, 177, 233)
end

1 comment
I'm not sure why you are checking if MouseButton1Click exists, as it is an event