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)
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.
You have to define RunService: local RunService = game:GetService("RunService"). And you can change the INCREMENT and the if conditions based on your preference.
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’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:
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)
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)
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