I made a simple script that changes the color of a textlabel’s text based on the color of the part. Use case? You have a part that needs a label but the part color could change in-game and make the text less visible.
screenshots of me changing the color and the text changing on the fly:
structure:
script:
local part = script.Parent.Parent.Parent
local THRESHOLD = .7 --brightness level to switch to black text
function setcolor()
local h,s,v = part.Color:ToHSV()
if v > THRESHOLD then
--black
script.Parent.TextColor3 = Color3.new(0.121569, 0.121569, 0.121569)
else
--white
script.Parent.TextColor3 = Color3.new(0.945098, 0.945098, 0.945098)
end
end
part:GetPropertyChangedSignal("Color"):Connect(function()
setcolor()
end)