Search code examples
luarobloxluau

Moving text from right to left


I'm working on a Roblox game, I want a TextLabel to move from right to left repeatadly and smoothly. Something like this: https://youtu.be/9f7xAxKtjXc

I have already tried to tween the Textlabel on hiting corner it will restart but it wasn't smooth. I'm expecting the TextLabel to move from right to left smoothly as in the video above.

Code I have tried:

local text = {script.Parent.TextLabel}

while wait() do
   for _,v in pairs(text) do
    local temp = v.Position.X.Scale
    if (temp <= -v.Size.X.Scale) then
       temp = 1.0
       end
       v.Position = UDim2.new(temp - 0.01, 0, 0.2, 0)
   end
end

Solution

  • local text = {script.Parent.TextLabel}
    
    while wait() do
        for _,v in pairs(text) do
            local temp = v.Position.X.Scale
            if (temp + 1.22 <= -v.Size.X.Scale) then
                temp = -0.016
            end
            v.Position = UDim2.new(temp - 0.01, 0, 0.2, 0)
        end
    end
    

    Change the TextLabel size to {0, 3298},{0, 70} and using this code it will be really smooth, just tweaked the values a little and it worked.