I have made a text effect where the text scrolls from the top left of the screen to the top right. When the text is half obscured, it appears on the other side.(Bolded because a lot of tutorials tween one text label offscreen then teleport it back after a delay)
However, I made this using 2 frames, both having 2 text labels with the same text, totalling 4 text labels. This works, but I was wondering if I could make it more efficient, maybe only using 2 text labels and tweeting them? I tried it, but I couldn’t seem to make it work past the first loop, or make it work with varying sized words.
Here’s my code:
local gui = script.Parent
local topbarA = gui.TopbarA
local topbarB = gui.TopbarB
local AScroll = tweenService:Create(topbarA,TweenInfo.new(5,Enum.EasingStyle.Linear),{Position = UDim2.fromScale(1,0)})
AScroll:Play()
AScroll.Completed:Connect(function()
topbarA.Position = UDim2.fromScale(0,0)
AScroll:Play()
end)
local BScroll = tweenService:Create(topbarB,TweenInfo.new(5,Enum.EasingStyle.Linear),{Position = UDim2.fromScale(1,0)})
BScroll:Play()
BScroll.Completed:Connect(function()
topbarB.Position = UDim2.fromScale(0,0)
BScroll:Play()
end)
Here’s how it is set up:
All TextLabels have an AnchorPoint of (0.5,0) and AutomaticSize X
Back TextLabels are Position (0,0,0,0)
Front TextLabels are Position (1,0,0,0)
TopbarA has an AnchorPoint of (1,0)
I figured out how to make this scrolling text effect with just two TextLabels and one TopBar. Basically what this does is control one label (the lead), has the other one follow behind the lead, and switches the leading label once the leading one goes far enough to the right.
local rs = game:GetService("RunService")
local Label1 = script.Parent.TopBar.Label1 --// AnchorPoint of both is {0.5, 0}
local Label2 = script.Parent.TopBar.Label2
local TravelTime = 4 --// How long it takes the center of a label to get from one edge of the screen to the other
local Switch = 0
rs.RenderStepped:Connect(function(dt)
local Main = if Switch == 0 then Label1 else Label2
local Other = if Switch == 0 then Label2 else Label1
Main.Position += UDim2.new(dt / TravelTime,0,0,0)
Other.Position = Main.Position - UDim2.new(1,0,0,0)
if Main.Position.X.Scale >= 1.5 then
Switch = math.abs(Switch - 1)
end
end)
Ah, thank you for pointing that out. It somehow never occurred to me that a boolean would also work just fine (and may also be better). My thought process started with have Switch be a number corresponding to the label numbers (1-2), and I eventually went to 0-1 so I could use math.abs(x - 1) from a part transparency toggle. Using numbers made so such sense that I simply never thought about using a boolean. Silly me.