Hi, all.
I’m trying to create a script that can estimate how many seconds a loading screen will take until it has reached 100%. I can’t figure out how to do this, so would anyone know?
Thanks!
Hi, all.
I’m trying to create a script that can estimate how many seconds a loading screen will take until it has reached 100%. I can’t figure out how to do this, so would anyone know?
Thanks!
Assuming this is related to ContentProvider:PreloadAsync
, I was able to create the following script(the formula being used is average time per asset * assets remaining):
local ContentProvider = game:GetService("ContentProvider")
local preload = {} --stuff to preload
--stolen from developer hub, loads random thumbnails
for i = 1, 200 do
table.insert(preload, "rbxthumb://type=Avatar&w=100&h=100&id=" .. math.random(1,1000000))
end
local total_assets = #preload
local finished_assets = 0
local total_time = 0
local start_time = os.clock()
ContentProvider:PreloadAsync(preload, function(id, success)
local finish_time = os.clock()
total_time += (finish_time-start_time)
finished_assets += 1
local average = total_time/finished_assets
local calculated = average*(total_assets-finished_assets)
print("seconds until finish:", calculated)
start_time = finish_time
end)
print("done")
Found a problem trying to get this script to work. It’s that there is nothing to preload. Probably should’ve mentioned this beforehand, but the game is loading terrain.
I’ve got a server script that updates a value with a percentage that is the amount of terrain loaded. The changes in this value are then picked up by a local script that displays the percentage value on screen.
So, how could I make this script work for that system?
Thanks!
--the script assumes NumValue is a value strictly between 0 and 100, which maxes at 100 every time
local NumValue = script.NumValue --path of updating value
local total_time = 0
local start_time = os.clock()
local old_value = NumValue.Value
local connection
connection = NumValue.Changed:Connect(function(value)
local finish_time = os.clock()
total_time += (finish_time-start_time)/(value-old_value)
local average = total_time/value
local calculated = average*(100-value)
print("seconds until finish:", calculated)
start_time = finish_time
old_value = value
if value == 100 then
connection:Disconnect()
print("done")
end
end)