I Tried making a Moving text but for some reason the text just randomly disappears after playing the tween
I Looked at each and every line and couldn’t find any error.
What was the issue?
The Code:
local dest = {}
dest.Position = UDim2.new(0,900,0,0)
local ti = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.In,math.huge,false,0)
local fin = tw:Create(script.Parent,ti,dest)
wait(2)
local tw2 = game:GetService("TweenService")
local dest2 = {}
dest2.Position = UDim2.new(0,0,0,0)
local ti2 = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.In,math.huge,false,0)
local fin2 = tw2:Create(script.Parent,ti2,dest2)
while true do
script.Parent.Position = UDim2.new(0,0,0,0)
fin:Play()
script.Parent.Position = UDim2.new(0,-900,0,0)
wait(3)
fin2:Play()
wait(3)
script.Parent.Position = UDim2.new(0,0,0,0)
end
script.Parent.Position = UDim2.new(0,0,0,0)
So I would really like to say there are a few things I personally would change about this script, but I’m just gonna help you with your problem first!
I’m like 100% certain this is being caused by your use of math.huge You are aware that you’re putting that in the repeatCount section of the tween right? You telling it to repeat a very large number of times?
Not only are you doing that, but you’re also looping those animations and making them play over themselves again and again.
This odd behavior is undoubtedly a problem with just really the entire way you’ve set up these tweens.
Here’s how I would change this:
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(3, Enum.EasingStyle.Linear)
local Destination1 = {Position = UDim2.new(0, 900, 0, 0)}
local Destination2 = {Position = UDim2.new(0, 0, 0, 0)}
local Tween1 = TweenService:Create(script.Parent, Info, Destination1)
local Tween2 = TweenService:Create(script.Parent, Info, Destination2)
while true do
Tween1:Play()
wait(3)
Tween2:Play()
wait(3)
end
If you’re interested, here’s a more in depth description of the many issues that were in your script.
This is more preference, but you don’t need to initialize tables before putting values in them.
Again, preference, but it helps to read your code better when you you more word friendly variable names.
You don’t need to specify every argument in most functions including TweenInfo.new(). The arguments you leave out will be auto filled with the defaults, which were what you had anyway.
You do not need to initialize TweenService twice, once you have it, you’re good.
You also didn’t need a 2nd TweenInfo either, it was all the same data, it doesn’t go away when you use it.
You didn’t need to set the position values manually, allow the tween to do all of the work for you.
Finally, since you had a while loop that never ended, no code under it would ever run, so changing the position under that loop did nothing as well.