Yes, I made a loading screen. But it sometimes shows me negative value. Is it a bug?
How do I fix this?
local Service = game:GetService("ContentProvider")
local Number = Service.RequestQueueSize
script.Parent.Parent.Enabled = true
while true do
wait()
local N = Service.RequestQueueSize
script.Parent.LoadingBar.Bar.Bar.Size = UDim2.new((Number - N)/Number,0,1,0)
if (Number - N)/Number ~= 1 then
script.Parent.Assetsleft.Text = "LoadingAssets("..(Number - N).."/"..Number..")"
else
script.Parent.Assetsleft.Text = "Loaded!"
wait(2.5)
local Service = game:GetService("TweenService")
local Info = TweenInfo.new(2,Enum.EasingStyle.Quart,Enum.EasingDirection.In,0,true,0)
local Goal = {}
Goal.BackgroundTransparency = 0
local Tween = Service:Create(script.Parent.Parent.Parent.Flash.Back,Info,Goal)
Tween:Play()
wait(2)
script.Parent.Parent.Enabled = false
script.Disabled = true
break
end
end
Perhaps the temporary fix is to use math.clamp to limit the range of the number from 0 to math.huge. However, the question is when is ContentProvider used to load assets?
Depending how many new assets and preloaded assets you have, there seems to be an error with the calculation of (Number - N) / Number. We still don’t know how many other assets are in. Also there might be momentary occurences where the RequestQueueSize is 0 at the very beginning.
The best fix to this is not to use RequestQueueSize at all. It is an arbitrary number that describes how many assets are queued to download. You are not supposed to use this for loading screens; depending on how aaset-intensive your game is, this number can be very large and keep players in loading screens for a while which is terrible UX.
What you should be doing instead is making use of PreloadAsync, only preloading the assets players need to have first thing upon entering (e.g. main menu icons, music and audio) and making your number based on your manufactured queue list. Downloading should otherwise be streamed in the background.