local B=""local i=5 local e=3 local u=i*e local F=320 local k=200 local j=11 local g=3 assert((numImages*i)*e>=g)local S=.3 assert(S>0)local Y=0 local D=0 local Z=g/S local v=0 local function h(B)v=math.fmod(v+B,S)D=math.floor(v*Z)+j local i=Y Y=math.floor(D/u)if i~=Y then imageInstance.Image=imageAssetIDs[Y+1]end local g=D-Y*u local h=math.floor(g/e)local x=g-h*e imageInstance.ImageRectOffset=Vector2.new(x*F,h*k)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(h)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=B Animator.Connection:Disconnect()end end return Animator
-- Placeholder texture can be any roblox asset link
local initialTexture = ""

local RowCount = 5
local ColCount = 3
local perImageSpriteCount = RowCount * ColCount
local width = 320
local height = 200
local startIndexOffset = 11

local framesInTotal = 3
assert(numImages * RowCount * ColCount >= framesInTotal)

local animPeriod = 0.3 -- period for the whole animation, in seconds
assert(animPeriod > 0)

local curImageIdx = 0
local curSpriteIdx = 0

local fps = framesInTotal / animPeriod
local accumulatedTime = 0

local function AnimateImageSpriteSheet(dt)
	accumulatedTime = math.fmod(accumulatedTime + dt, animPeriod)
	curSpriteIdx = math.floor(accumulatedTime * fps) + startIndexOffset

	local prevImageIndex = curImageIdx
	curImageIdx = math.floor(curSpriteIdx / perImageSpriteCount)
	if prevImageIndex ~= curImageIdx then
		imageInstance.Image = imageAssetIDs[curImageIdx + 1]
	end

	local localSpriteIndex = curSpriteIdx - curImageIdx * perImageSpriteCount
	local row = math.floor(localSpriteIndex / ColCount)
	local col = localSpriteIndex - row * ColCount
	imageInstance.ImageRectOffset = Vector2.new(col * width, row * height)
end

Animator.Connection = nil

Animator.Init = function()
	Animator.Connection = game:GetService("RunService").RenderStepped:Connect(AnimateImageSpriteSheet)
end

Animator.Stop = function()
	if Animator.Connection then
		imageInstance.Image = initialTexture
		Animator.Connection:Disconnect()
	end
end

return Animator
