How would I make the brightness inverted, and not go lower?

So my problem is that the brightness of the light (Light.Brightness at line 42) goes lower the more items i add to the ‘display’ surfacegui, even though they are 0 on the transparency

local Light = script.Parent
local Display = script.Parent.Parent.Display

local aR, aG, aB, aT = {}, {}, {}, {}

local function average(t)
	local sum_num = 0
	for _, num in pairs(t) do
		sum_num += num
	end
	
	local avg = sum_num / #t
	
	return avg
end

while true do
	for _, obj in pairs(Display:GetDescendants()) do
		if obj:IsA("ImageLabel") or obj:IsA("ImageButton") then
			table.insert(aR, obj.ImageColor3.R or 0)
			table.insert(aB, obj.ImageColor3.G or 0)
			table.insert(aG, obj.ImageColor3.B or 0)
			
			table.insert(aT, obj.ImageTransparency or 0)
		elseif obj:IsA("TextLabel") or obj:IsA("TextButton") or obj:IsA("TextBox") then
			table.insert(aR, obj.TextColor3.R or 0)
			table.insert(aB, obj.TextColor3.G or 0)
			table.insert(aG, obj.TextColor3.B or 0)
			
			table.insert(aT, obj.TextTransparency or 0)
		end
		
		table.insert(aR, obj.BackgroundColor3.R or 0)
		table.insert(aG, obj.BackgroundColor3.G or 0)
		table.insert(aB, obj.BackgroundColor3.B or 0)
		
		table.insert(aT, obj.BackgroundTransparency or 0)
	end
	
	local avgColor3 = Color3.new(average(aR), average(aB), average(aG))
	Light.Color = avgColor3
	Light.Brightness = math.floor(math.abs(average(aT)))
	
	task.wait(1)
	table.clear(aR) table.clear(aG) table.clear(aB) table.clear(aT)
end

i dont see a variable for average so im assuming this isnt the full code or im blind

2 Likes

you are blind
its a function

check again lol

1 Like

another thing ive spotted is u have a lot of the values mixed up is this on purpose


image

1 Like

also what is your aim its unclear in your post the reason why it gets dimmer the more items you add is because you are dividing the end brightness value by the number of items you have

the average function:

local avg = sum_num / #t
1 Like

i just converted some code i found for python so i dont know whats wrong

it should get brighter the more items that have transparency on 0, or if its 1, it should get dimmer

1 Like

this code doesnt look like its going to do that theres not a single check for if the brightness has reached the 0 or 1 limit

additionally this code seems extremely overdone for something that simple your better off not using a converter and just coding it from scratch like what is the need for math.abs in this situation and math.floor

2 Likes