How to make moving background scroll infinitely?

Hey devforum! I am trying to create a GUI background that is infinitely moving to the side , i saw a same topic but that still not working. Could someone can help me?

Here is the script :

local image = script.Parent

local function whenTweenCompleted(state)

	if state == Enum.TweenStatus.Completed then

		image.Position = UDim2.new(0, 0, -0.5, 0)

	end
end

image:TweenPosition(UDim2.new(-1, 0 -0.5, 0), "Out", "Linear", 45, false, whenTweenCompleted)

Here is my pattern :

and here is the result :

Here is what i want :

8816b27abb3d434edb2341ce08a4fef33d38ce71

Maybe this will help:

task.spawn(function()
    local x, y = 0, 0
    local INCREMENT = 0.1

    while RunService.Heartbeat:wait() do
        image.Position = UDim2.fromScale(x, y)

        x -= INCREMENT
        if x < -1 then x = 0 end

        y -= INCREMENT
        if y < -0.5 then y = 0 end
    end
 end)

Edit: I just saw your issue – your image is moving out of the screen. Maybe scaling your image to a bigger/out-of-the-screen size will help. Try this: image.Size = UDim2.fromScale(2, 2) and change the AnchorPoint to accommodate the size.

Captazdadadaure
i have an error here

You have to define RunService: local RunService = game:GetService("RunService"). And you can change the INCREMENT and the if conditions based on your preference.

Actually this is what appears x) :

xD

Try lowering the increment; put the 1 behind another 0 or two. And if that does not work, I can help with tweening. But, changing the size of your image was definitely needed.

i just set the INCREMENT to 0.01 and here is the result :

There is a typo here, you are missing the second comma in the UDim2.new() initialisation.

where i need to put the second comma in the UDim2.new() ?? bcs actually idk

This should be:

UDim2.new(-1, 0, -0.5, 0)

I’m not offering this as a solution but if you have other code working on this, or you are following a tutorial or using others code it might help somewhat.

Even easier to use - if you are only using scales rather than offsets - is this UDim2 constructor:

UDim2.fromScale(-1,-0.5);

Here you go:

task.spawn(function()
	while true do
		local info = TweenInfo.new(--[[insert time]], Enum.EasingStyle.Linear)
		local goal = {Position = UDim2.fromScale(-1, 0)}

		local tween = TweenService:Create(background, info, goal)
		tween:Play()

		tween.Completed:Wait()
		
		background.Position = UDim2.fromScale(0, -1)
	end
end)

I tested this code, and it works for me.

that still not working for me :frowning:

could you send me your plate pls ?

( here is the script )

local image = script.Parent
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

task.spawn(function()
	while true do
		local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
		local goal = {Position = UDim2.fromScale(-1, -1)}

		local tween = TweenService:Create(image, info, goal)
		tween:Play()

		tween.Completed:Wait()

		image.Position = UDim2.fromScale(0, 0)
	end
end)

Change image.Position = UDim2.fromScale(0, 0) to image.Position = UDim2.fromScale(-1, 0); change local goal = {Position = UDim2.fromScale(-1, -1)} to local goal = {Position = UDim2.fromScale(0, -1)}.

And sure, I will send you a link to my open-source game.

not working actually i dont have my image now

OK. Maybe this will help. Here are my ImageLabel's properties:
image
image

Damn why for me its not working?

It seems like my previous code is interfering with my current. Also, here is the open-source game’s link: Moving Background Template

could you try with my image to see if that work or no?

thanks but your place is private and i can’t download the plate

OK. I updated the place. Also, your issue may be that you are not using a singe image. I am using a single image, and converting that into tiles. Take one of these


and change it to this:
image