You can’t only tween specific properties because you don’t know which properties to specifically tween. Sometimes sure; you won’t want to tween their background transparency and just leave it transparent, but other times you might want to make it partially visible while keeping the same ratio of visibility on all the other objects. It’s not as easy as you think it is. Here’s the order of operations:
- Create a Terpy object using a container and cache every transparency related property key and value of each descendant of that container (which is the hardest part of this whole process). Example:
local originalTransparencies = {
TextLabel = {
TextTransparency = 0,
TextStrokeTransparency = 1,
BackgroundTransparency = .5
},
}
- Now we tween it. So let’s say I wanted to tween the TextLabel only partially transparent. You might think the typical tween each property to that value would work:
TS:Create(TextLabel, TweenInfo.new(1), {
TextTransparency = .5,
BackgroundTransparency = .5,
TextStrokeTransparency = = .5
})
But there’s an issue, we don’t want the text stroke to become as visible as the background transparency, or the background transparency to be just as visible as the text because we initially had one at 0, one at 1, and one at .5. The better solution would be to tween them to .5, 1, and .75 respectively. In order to tween the whole object “50 percent” more transparent (the whole object being like a model, screen gui, billboard gui, with lots of different types of descendants), we need to linear interpolate (lerp) their starting values to completely transparent by the given percentage (being .5 in this case).
That’s where the original properties comes in (not to mention saving all of those property names to tween every single time instead of re collecting them). We can just lerp original transparency + (1 - goal transparency) * the percent
. So instead of tweening them all to .5 and screwing up the overall look of our container and it’s objects, using the lerp we would tween invisible “50 percent” like this:
local function lerp(a, b, t)
return a + (b - a) * t
end
local percentToTransparent = .5
TS:Create(TextLabel, TweenInfo.new(1), {
TextTransparency = lerp(originalTextTransparency, 1, percentToTransparent), -- This would just be .5
BackgroundTransparency = lerp(originalBackgroundTransparency, 1, percentToTransparent), -- This would become .75 instead of .5 to maintain the same ratio (starting at .5 and tweening %50 percent of the way to transparent)
TextStrokeTransparency = lerp(originalTextStrokeTransparency, 1, percentToTransparent) -- This would just stay 1 because it's already transparent
})
You might notice when the ProximityPromptGui gets all bad looking in the demo during the loop. This is because I used the ignoreOriginalTransparencies
boolean for the Terpy:SetTransparency()
method. It did exactly what I just said we don’t want to do in most situations. That’s why it’s an optional argument, and defaults to true if not passed into the call. Because we almost always want to only tween relative to their original transparencies, not just hardset them to the passed transparency.