Simple preloader

I made a simple preloader that you can use to create loading screens
This preloader has auto retry on timeout, the default retry amount is 5.

Which means this module will retry 5 times every 1 second, but you can change that in the module.

API:

Methods:


Module.new() → Constructor

Creates a new constructor


Constructor:Add( content : string | Folder , Priority : number? )

You can add a content id or a folder, to load in.
The default priority is 2 which is low.

High - 1
Low - 2

Content with high priority will load first and if it fails, it retry.


Constructor:Load()

Loads all the content

yields


Constructor:GetItemsToLoad(priority : number?)

Gets the items to load (it returns all the content ids), leave priority blank to return ALL the items to load from both priorities.


Properties

Module.PriorityType → { HIGH = 1; LOW = 2 }

PriorityType.HIGH | PriorityType.LOW

HIGH = 1
LOW = 2


Constructor.prioritiesStatus → { High = { Failed = {}, Loaded = {} }, Low = { Failed = {}, Loaded = {} } }

Returns all the content ids for each priority in failed or loaded table.


Feel free to customize it to your liking, you can use signal to add events to check for once a priority/item loads or use promises etc.

This is just a simple and quick preloader I made that anyone can use in their games.
This module is not maintained.

Get it here:

7 Likes

Usage:


Simple debugging:

local preloader = require(module)
local folderToLoad = folder_here

local loader = preloader.new()
loader:Add(folderToLoad , loader.PriorityType.HIGH)
local itemsToLoad = loader:GetItemsToLoad(loader.PriorityType.HIGH)
local allItemsToLoad = loader:GetItemsToLoad()

print(`High Priority Items: {#itemsToLoad}, loading..`)
loader:Load()

local loadedAmount = #itemsToLoad - #loader.prioritiesStatus.High.Failed
local failedAmount = #itemsToLoad - #loader.prioritiesStatus.High.Loaded

print(`✅ Completed loading: {loadedAmount}`)
print(`❌ Failed to load: {failedAmount}`)
print(`📊 {math.floor((loadedAmount/#itemsToLoad) * 100)}% were loaded.`)

print(loader.prioritiesStatus.High)

Loading Screen:

local preloader = require(module)

local animations = folder_here
local images = folder_here

local loader = preloader.new()

loader:Add(animations , loader.PriorityType.HIGH)
loader:Add(images, loader.PriorityType.LOW)

loader:Load()

print('Loading done.')

Pretty nice and simple module!

The usage is very straightforward and I like the simplicity of it all.

Thank you for this resource!

1 Like