local s=""local U=5 local p=3 local c=U*p local B=320 local q=200 local f=26 assert((numImages*U)*p>=f)local o=1 assert(o>0)local x=0 local N=0 local h=f/o local R=0 local function E(s)R=math.fmod(R+s,o)N=math.floor(R*h)local U=x x=math.floor(N/c)if U~=x then imageInstance.Image=imageAssetIDs[x+1]end local f=N-x*c local E=math.floor(f/p)local m=f-E*p imageInstance.ImageRectOffset=Vector2.new(m*B,E*q)end Animator.Connection=nil Animator.Init=function()Animator.Connection=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(E)end Animator.Stop=function()if Animator.Connection then imageInstance.Image=s 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 framesInTotal = 26
assert(numImages * RowCount * ColCount >= framesInTotal)

local animPeriod = 1 -- 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)

	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
