Came across this, and despite it being over 2 years old and there now being an Instance for this (albeit still in Beta), I’m here with some modifications to accommodate for pre-existing Transparency.
Updated Source
local module = {}
local function calculateTransparency(orig, factor)
return orig + (1 - orig) * factor
end
local function set(inst: Instance, prop: string, factor: number)
inst[prop] = calculateTransparency(inst:GetAttribute(`CG_{prop}`), factor)
end
local function fixDescendants(canvasGroup, bool)
local doStrokes = false
if bool then
doStrokes = true
end
set(canvasGroup.Parent, 'BackgroundTransparency', canvasGroup.Value)
for canvas, descendant in pairs(canvasGroup.Parent:GetDescendants()) do
if descendant:IsA("GuiObject") then
set(descendant, 'BackgroundTransparency', canvasGroup.Value)
if descendant:IsA("TextLabel") or descendant:IsA("TextButton") or descendant:IsA("TextBox") then
set(descendant, 'TextTransparency', canvasGroup.Value)
if doStrokes then
set(descendant, 'TextStrokeTransparency', canvasGroup.Value)
end
elseif descendant:IsA("ImageButton") or descendant:IsA("ImageLabel") then
set(descendant, 'ImageTransparency', canvasGroup.Value)
end
end
end
return nil
--[[
Test Cases:
[
[ 1, 0.5, 1 ],
[ 0, 0.5, 0.5 ],
[ 0.5, 0.5, 0.75 ],
[ 1, 0, 1 ],
[ 0, 0, 0 ],
[ 0.5, 0, 0.5 ],
[ 1, 1, 1 ],
[ 0, 1, 1 ],
[ 0.5, 1, 1 ],
[ 1, 0.25, 1 ],
[ 0, 0.25, 0.25 ],
[ 0.5, 0.25, 0.625],
]
]]
end
function module:Create(parent, value, bool)
local numberVal = Instance.new("NumberValue")
local key = "CanvasGroup"
numberVal.Name = key
numberVal.Value = value
numberVal.Parent = parent
numberVal.Parent:SetAttribute("CG_BackgroundTransparency", numberVal.Parent.BackgroundTransparency)
for _, descendant in ipairs(numberVal.Parent:GetDescendants()) do
if descendant:IsA("GuiObject") then
descendant:SetAttribute("CG_BackgroundTransparency", descendant.BackgroundTransparency)
if descendant:IsA("TextLabel") or descendant:IsA("TextButton") or descendant:IsA("TextBox") then
descendant:SetAttribute("CG_TextTransparency", descendant.TextTransparency)
descendant:SetAttribute("CG_TextStrokeTransparency", descendant.TextStrokeTransparency)
elseif descendant:IsA("ImageButton") or descendant:IsA("ImageLabel") then
descendant:SetAttribute("CG_ImageTransparency", descendant.ImageTransparency)
end
end
end
numberVal:GetPropertyChangedSignal("Value"):Connect(function()
fixDescendants(numberVal, bool)
end)
numberVal.Parent.ChildAdded:Connect(function()
fixDescendants(numberVal, bool)
end)
fixDescendants(numberVal, bool)
return numberVal
end
return module