--tommy * 2024 (@__tommyy) local RunService = game:GetService("RunService") local Players = game:GetService("Players") local Sequence = {} Sequence.Assets = {} local TotalImages = 0 local ImagesLoaded = 0 for _, SpritesheetDefinition in script:GetChildren() do local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui") local TemporaryLoadingGui = Instance.new("ScreenGui", PlayerGui) TemporaryLoadingGui.Name = "TemporaryLoader" local ReturnedSpritesheetDefinition = require(SpritesheetDefinition) Sequence.Assets[SpritesheetDefinition.Name] = {} local SpriteSheetDataContainer = Sequence.Assets[SpritesheetDefinition.Name] SpriteSheetDataContainer.Definition = ReturnedSpritesheetDefinition if ReturnedSpritesheetDefinition.AssetId then TotalImages += 1 local NewImageLabel = Instance.new("ImageLabel", TemporaryLoadingGui) NewImageLabel.Size = UDim2.fromOffset(1, 1) NewImageLabel.Image = ReturnedSpritesheetDefinition.AssetId NewImageLabel.BackgroundTransparency = 1 NewImageLabel.Name = SpritesheetDefinition.Name SpriteSheetDataContainer.Image = NewImageLabel NewImageLabel.ImageTransparency = 0 task.spawn(function() while not NewImageLabel.IsLoaded do RunService.RenderStepped:Wait() end ImagesLoaded += 1 NewImageLabel.ImageTransparency = 1 end) elseif ReturnedSpritesheetDefinition.AssetIds then if not SpriteSheetDataContainer.Images then SpriteSheetDataContainer.Images = {} end TotalImages += ReturnedSpritesheetDefinition.FrameCount for ImageIndex = 1, ReturnedSpritesheetDefinition.FrameCount do local NewImageLabel = Instance.new("ImageLabel", TemporaryLoadingGui) NewImageLabel.Size = UDim2.fromOffset(1, 1) NewImageLabel.Image = ReturnedSpritesheetDefinition.AssetIds[ImageIndex] NewImageLabel.BackgroundTransparency = 1 NewImageLabel.Name = `{SpritesheetDefinition.Name}_{ImageIndex}` SpriteSheetDataContainer.Images[ImageIndex] = NewImageLabel NewImageLabel.ImageTransparency = 0 task.spawn(function() while not NewImageLabel.IsLoaded do RunService.RenderStepped:Wait() end print(`Image {SpritesheetDefinition.Name} #{ImageIndex} loaded`) ImagesLoaded += 1 NewImageLabel.ImageTransparency = 1 end) end end end while ImagesLoaded < TotalImages do RunService.RenderStepped:Wait() end print(`Loaded {ImagesLoaded} images for ImageSequence`) function Sequence.PlaySequenceTrueSpritesheet(ImageLabel: ImageLabel, SpritesheetDefinition, DoLoop: boolean) local FrameCount = SpritesheetDefinition.Definition.FrameCount local FrameSize = SpritesheetDefinition.Definition.FrameSize local FrameTime = SpritesheetDefinition.Definition.FrameTime local GridSize = SpritesheetDefinition.Definition.GridSize local AssetId = SpritesheetDefinition.Definition.AssetId ImageLabel.Image = AssetId ImageLabel.ImageRectSize = FrameSize local LoopThread; LoopThread = coroutine.create(function() local TimeElapsed = 0 local ImageIndex = 0 while coroutine.status(coroutine.running()) ~= "dead" do TimeElapsed += RunService.RenderStepped:Wait() if TimeElapsed >= FrameTime then TimeElapsed -= FrameTime local OffsetX = FrameSize.X * (ImageIndex % GridSize.X) local OffsetY = FrameSize.Y * math.floor(ImageIndex / GridSize.X) ImageLabel.ImageRectOffset = Vector2.new(OffsetX, OffsetY) ImageIndex += 1 if ImageIndex == FrameCount - 1 then if DoLoop then ImageIndex = 0 else break end end end end end) coroutine.resume(LoopThread) return function() coroutine.close(LoopThread) end end function Sequence.PlaySequenceButRobloxIsBad(ImageLabel: ImageLabel, SpritesheetDefinition, DoLoop: boolean) local FrameCount = SpritesheetDefinition.Definition.FrameCount local FrameTime = SpritesheetDefinition.Definition.FrameTime local AssetIds = SpritesheetDefinition.Definition.AssetIds ImageLabel.Image = "rbxassetid://0" ImageLabel.ImageRectSize = Vector2.zero ImageLabel.ImageRectOffset = Vector2.zero local LoopThread; LoopThread = coroutine.create(function() local TimeElapsed = 0 local ImageIndex = 1 while coroutine.status(coroutine.running()) ~= "dead" do TimeElapsed += RunService.RenderStepped:Wait() if TimeElapsed >= FrameTime then TimeElapsed -= FrameTime local AssetId = AssetIds[ImageIndex] if AssetId then ImageLabel.Image = AssetId end ImageIndex += 1 if ImageIndex == FrameCount then if DoLoop then ImageIndex = 1 else break end end end end end) coroutine.resume(LoopThread) return function() coroutine.close(LoopThread) end end function Sequence.PlaySequence(ImageLabel: ImageLabel, SpritesheetDefinition, DoLoop: boolean) return (SpritesheetDefinition.Definition.AssetId and Sequence.PlaySequenceTrueSpritesheet or Sequence.PlaySequenceButRobloxIsBad)(ImageLabel, SpritesheetDefinition, DoLoop) end return Sequence