Need help making this asset loader go faster

Hello i need some help making this faster

i need it to get to 5367 in 7 seconds but idk how
if i remove the wait the game just crashes

– i couldnt make a video cause file was to big

while true do
	wait()
	Time.Value = Time.Value + 1
	script.Parent.AssetsText.Text = "Loading Assets"..Time.Value.."/5367"
	if Time.Value == 5367 then
		script.Parent.Parent.LoadingGui:Destroy()
	end
end

Wait(.001) should reach 7000 in 7 seconds

It’s impossible to wait that short of an interval.

1 Like

I think minimum wait() is 29 milliseconds (.029 seconds), but it could be higher depending on the load on the computer.

I took the math approach, I don’t deal with anything less than .03.

The obvious answer is you cant count by one

wait() can only run at most 30 times a second, and can be throttled when the engine is slow.

This will interpolate over the course of 7 seconds by figuring out what the count should be based on how much time has passed.

local DURATION = 7 -- Seconds to complete
local TOTAL_COUNT = 5367

local startTime = os.clock()
while true do
	local percent = math.clamp((os.clock()-startTime)/DURATION, 0, 1)
	local count = math.floor(percent * TOTAL_COUNT)
	local text = "Loading Assets "..count.."/"..TOTAL_COUNT
	script.Parent.AssetsText.Text = text
	if percent >= 1 then
		break
	end
	wait()
end
script.Parent.Parent.LoadingGui:Destroy()

The fastest way you’d be able to count with something like that is either with task.wait() which will resume on the next update or renderstepped, as both of these update per frame. RenderStepped will be more reliable however I believe the best method is to just use VitalWinters method, it’s simple and works as a simple loading screen.

What’s the point in making an artificial loading screen like this? Your aim should be to get a player to jump into the gameplay ASAP, so your loading screen should realistically only be used so you can do some background prep or load assets that’ll be immediately visible by the player.

ContentProvider provides you a way to prioritise assets to be downloaded, so you could create a list of the instances you want downloaded first and then give an estimate as to how long that’d take. I do not personally recommend or endorse using RequestQueueSize for a loading screen though.

If you aren’t loading anything then no point in making a loading screen. Your loading screen should be dependent on actually loading in assets or preparing the game, not speedrunning a counter.

4 Likes