I’m making a subtitles system, and I want all the subtitles to tween in smoothly, along with the bar that holds all the subtitles. Once the subtitle is destroyed, I want the GUI to tween back to it’s original size (before the subtitle was added)
Currently my code destroys the subtitle, but that causes the GUI to snap to the new position rather than tweening smoothly. I’m using UIListLayout.
Current subtitle code
local subtitle = {}
local amount = 0
function subtitle.New(text : string, decay : number, tweenInfo : TweenInfo, gui : ScreenGui)
local BarContainer : Frame = gui:FindFirstChild("BarContainer")
if BarContainer then
print(BarContainer)
local SubtitleTemplate : TextLabel = BarContainer:FindFirstChild("SubtitleTemplate")
if SubtitleTemplate then
amount += 1
print(SubtitleTemplate)
local newSubtitleObject = SubtitleTemplate:Clone()
newSubtitleObject.Text = text
newSubtitleObject.Name = "NewSubtitle_" .. amount
-- Set text transparency to 1, we're gonna fade it in later
newSubtitleObject.TextTransparency = 1
-- Get original size, we're gonna tween back to this before the subtitle is destroyed.
-- Setup tweens for later
local SubtitleFadeIn = TweenService:Create(newSubtitleObject, tweenInfo, {TextTransparency = 0})
local SubtitleFadeOut = TweenService:Create(newSubtitleObject, tweenInfo, {TextTransparency = 1})
-- Parent it
newSubtitleObject.Parent = BarContainer
-- Set subtitle to visible then immediately play the tween after.
newSubtitleObject.Visible = true
SubtitleFadeIn:Play()
-- Wait (decay) and fade out.
task.wait(decay)
SubtitleFadeOut:Play()
-- Wait for tween to finish
SubtitleFadeOut.Completed:Wait()
-- Destroy subtitle object
newSubtitleObject:Destroy()
end
else
warn("Subtitle GUI is invalid! Did you supply the correct GUI?")
end
end
return subtitle
A good example of the effect I want to achieve is attached, from the game Innovation Inc. Thermal Power Plant