Scripting a moving background screen

Basically, what I usually do is create an image that can have a repeating pattern, like this image here:
moving background test
I made an image label and set its size to {2, 0}, {2, 0} and use the TileSize property which becomes visible if you set the image’s ScaleType to Tile:
image

In a script, you can use TweenService or TweenPosition to move the image to a position then restore it to its previous position at the end of the tween:

local TweenService = game:GetService("TweenService")

local tween = TweenService:Create(script.Parent, TweenInfo.new(10, Enum.EasingStyle.Linear), {Position = UDim2.new(0, 0, -1)})

while true do
	script.Parent.Position = UDim2.new(-1)
	tween:Play()
	tween.Completed:Wait()
end

When running this, you should see that it continually moves to the top-right:

If you want it to go to horizontally, vertically, or diagonally, here’s the position you’d need to begin at and target:

  • To the right: Start at {-1, 0}, {0, 0}; End at {0, 0}, {0, 0} (To the left is the opposite)
  • To the top: Start at {0, 0}, {0, 0}; End at {0, 0}, {-1, 0} (To the bottom is the opposite)
  • To the top-right: Start at {-1, 0}, {0, 0}; End at {0, 0}, {-1, 0} (To the bottom-left is the opposite)

This should give you some insight on how to achieve this

57 Likes