Fix image scrolling effect

Hey, so I’m making a UI effect module, and so far I’ve made 2 effects, but for my third I wanted to give users the ability to easily make scrolling backgrounds to their frames. It works almost perfectly, and I tested it with a grid pattern and it looked fine, but I switched to a hounds tooth plaid pattern and sometimes it bugs out. Does anyone know how to fix this? Help would be greatly appreciated!

local function animateBackground(gui, speed)
	if gui.Position.X.Scale >= 1.5 and gui.Position.Y.Scale >= 1.5 then
		gui.Position = UDim2.fromScale(0.5, 0.5)
	end
	local calcSpeed = speed * 0.01
	gui.Position = UDim2.fromScale(gui.Position.X.Scale + calcSpeed, gui.Position.Y.Scale + calcSpeed)
end
local roInFrame = Instance.new("ImageLabel")
		roInFrame.AnchorPoint = Vector2.new(0.5, 0.5)
		roInFrame.Position = UDim2.fromScale(0.5, 0.5)
		roInFrame.Size = UDim2.fromScale(3, 3)
		roInFrame.Name = "RoInAnimatedFrame"
		roInFrame.ScaleType = Enum.ScaleType.Tile
		roInFrame.TileSize = UDim2.fromScale(tileSize, tileSize)
		roInFrame:SetAttribute("Speed", speed)
		if imageId ~= nil then
			roInFrame.Image = "rbxassetid://"..math.abs(imageId)
		else
			roInFrame.Image = "rbxassetid://6926739735"
		end
		roInFrame.Parent = self.Container
		self.AnimatedBackground = roInFrame
		animatedBGs[#animatedBGs + 1] = roInFrame
	end

The function I provided is pretty self explanitory, the gui argument is the ImageLabel that is moving, and the speed parameter is passed in by the user to control how fast it moves. The second snippet I provided is what creates the ImageLabel, so you can see it’s properties.
I know this probably has to do with me resetting the position back to 0.5, 0.5, but if I don’t reset the position, of course it will just move infinitely off to the side.