Terpy (tween large models and guis' overall transparency with ease)

Terpy

(Ignore the strange name, it works well :grin:)

This is a module for tween a container’s descendants back and forth from transparent to non-transparent while maintaining their original properties!

Example usage:

-- In a LocalScript in StarterPlayerScripts

local Terpy = require(script.Terpy)

local dummyModelTerpy = Terpy.new(workspace.Dummy)
local goalTransparency = 1
local ignoreOriginalTransparencies = true

dummyModelTerpy:SetTransparency(goalTransparency, ignoreOriginalTransparencies) -- Sets the model completely invisible (all descendants with transparency related properties get this value)

task.wait(2)

local tweenInfo = TweenInfo.new(1)
goalTransparency = 0

dummyModelTerpy:TweenTransparency(tweenInfo, goalTransparency) -- Tweens the model back to its original visibility (all descendants with transparency related properties go back to their original values)

Demo:

Roblox Model: Terpy - Roblox


If you have any questions or concerns please let me know by replying to this topic, thanks!

25 Likes

Why not use a loop? Only tweening specific properties does not mess up other properties.

2 Likes

What’s stopping you from doing this?

wait(2)
local TweenService = game:GetService("TweenService")
local Goals = {
	Transparency = 1
}
local Info = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
for i,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("BasePart") then
		print('f')
		local tween = TweenService:Create(v, Info, Goals)
		tween:Play()
	end
end
1 Like

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:

  1. 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
 },
}
  1. 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.

6 Likes

This makes more sense. You should market it as more of a Visible tween since it basically functions as if you could tween the Visible value of a UI object.

1 Like

Yes, that would make more sense and possibly clear up confusion on what the goalTransparency argument really means.

So… I am currently working on my game and for my loading screen and credits I’m trying to use this.

I set the frame to visible and then immediately use the set transparency function in your module to make it transparency 1. After, I use the tween function to animate it to being visible.

However, when I do this. It does not remember the values from before and the only way I can successfully tween it is if I make every transparency property set to 0.

Do you know any way I can avoid this situation and have it function properly for my intended purpose? Or is this simply out of this modules scope and I am left with no options.

1 Like

Idk, it’s probably more convenient to just plop in a module and use it instead of typing all that out. It’s just from my experience

Ah! Are you expecting the Terpy container’s transparency to also be changed like its descendants? If so, then it’s not going to work as expected. I recently encountered this as well and updated the module accordingly. I haven’t published it yet, but I can now. Sorry for the inconvenience.

1 Like

Terpy v1.1.0


Additions

  • Added boolean includeContainer for constructing a new Terpy instance.

  • Added type definitions to help differentiate between Terpy static and a Terpy instance with autocomplete.

  • Added some term definitions for different terms commonly used throughout the documentation.

1 Like

Thank you.

I quickly put together a GUI to test terpy now and it seems to be working fine!

1 Like

One more question. Is there any possible way to have multiple animations running at once with different containers. Because the animation that I run with a different container is cancelled out by the next one I run.

Hmm that shouldn’t be happening. Could you show some code?

1 Like

I have the screenshot here.

You can see the code on the final tween (end of function) where the .completed function should run. However, it is cancelled by the terpy animation that is ran on the next loop

Terpy - Animation: Screen faded in (x4)

The “Terpy - Animation: Screen faded out” is never printed once in the output

1 Like

Wow, I had overlooked two major bugs. Thank you so much for bringing this to my attention.

1 Like

Terpy v1.1.1


Bug Fixes

  • Fixed tweens not being discarded after playing.

  • Fixed canceling tweens that were not playing which triggered the ‘Tween.Completed’ event.

  • Fixed ‘Terpy:SetTransparency()’ not setting the Terpy.Transparency property to the passed goalTransparency.

  • Fixed ‘Terpy:SetTransparency()’ not canceling tweens before setting the transparency.

1 Like

Terpy v1.2.0


Changes (non-breaking)

  • Removed the optional includeContainer boolean that was passed when constructing a new Terpy instance. The cache function already checks to see if objects are able to be cached as “Terpy objects” (objects with transparency related properties). No issue with just throwing the container into that function as well.
    TLDR: The Terpy’s container is automatically included now.

Bug Fixes

  • Fixed UIStrokes’ transparencies not being tweened (the module was made before they were public).
3 Likes

Terpy v1.2.1


Bug Fixes

  • Fixed some method typing issues.

Terpy v1.3.0


Additions

  • Added boolean startTransparent for constructing a new Terpy instance.

  • Added Terpy:Destroy() method that gets called automatically when the Terpy instance is destroyed.

Bug Fixes

  • Fixed descendants being added or removed to the container not being affected by the Terpy.

Terpy v1.3.1


Bug Fixes

  • Fixed ScrollBarImageTransparency not being spelled correctly and causing errors when trying to tween a scrolling frame’s transparency.