I can guarantee you that my computer isn’t the greatest, so when I created a loading bar and it instantly loads 2,000+ assets instantaneously, it peaks my suspicion.
This is the code I’m using for the loading bar:
Code
local Assets = game.Workspace:GetChildren()
for i = 1, #Assets do
local asset = Assets[i]
CP:PreloadAsync({asset})
local progress = i / #Assets
local bar = Player.PlayerGui.Intro.LoadingAssets.Loading
Player.PlayerGui.Intro.LoadingAssets.Assets.Text = i .. "/" .. #Assets
bar.Size = UDim2.new(progress, 0, 0.111, 0)
end
The Problem:
As mentioned before, it loads instantly, there is no count up to the number of assets, nor does the bar gradually increase, it just finishes as soon as I join the game. I wanted to use this as an asset loader for when players joined my game, and to test it out, I duplicated a bunch of parts into the workspace (2k+). The code I used is almost directly related to that in which was provided at
And I’ve also looked into RequestQueueSize, but that returns a solid 0 which is unhelpful with a loading screen.
local Assets = game.Workspace:GetChildren()
for i = 1, #Assets do
local asset = Assets[i]
CP:PreloadAsync({asset})
local progress = i
local bar = Player.PlayerGui.Intro.LoadingAssets.Loading
Player.PlayerGui.Intro.LoadingAssets.Assets.Text = i .. "/" .. #Assets
bar.Size = UDim2.new(progress, 0, 0.111, 0)
end
This wouldnt work, since the UDim2 scale value for X would then be 1 and would increase by 1 each iteration making the bar upwards of 2,000x my screen length.
Is this in studio? In studio everything should load nearly instantly. If it’s not in studio it might just be already loaded when you join, or it could be the workspace and its children not loading in before the script runs. Is there any reason you can’t use game.Loaded? Once that fires it means all localscripts can run without needing to worry about something not being loaded, and anything that is sent in the snapshot
from the server doesn’t need a :WaitForChild(). If you really need this loading screen, you would need to put this script in replicatedfirst and use RemoveDefaultLoadingScreen
Once I get home, ill share the full script, it is a local script in replicatedfirst. I’m going to be using the local script to create an intro to my game. Dont know if this helps any.
local TweenServ = game:GetService("TweenService")
local CP = game:GetService("ContentProvider")
print(CP.RequestQueueSize)
local Player = game.Players.LocalPlayer
--local character = Player.Character or Player.CharacterAdded:Wait()
local UI = script:WaitForChild("Intro"):Clone()
UI.Parent = Player:WaitForChild("PlayerGui")
if not game:IsLoaded() then
game.Loaded:Wait()
end
game.ReplicatedFirst:RemoveDefaultLoadingScreen()
function TweenerForLinearUIs(Object,Time,UDimVal)
local newtween = TweenServ:Create(Object,TweenInfo.new(Time,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0),{Position = UDimVal})
newtween:Play()
return newtween
end
if CP.RequestQueueSize >0 then
print("yooo")
local rotation = TweenServ:Create(Player.PlayerGui.Intro.LoadingAssets,TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,true,0),{Rotation = 10})
rotation:Play()
print("Sup")
local Assets = game.Workspace:GetChildren()
for i = 1, #Assets do
local asset = Assets[i]
CP:PreloadAsync({asset})
local progress = i / #Assets
local bar = Player.PlayerGui.Intro.LoadingAssets.Loading
Player.PlayerGui.Intro.LoadingAssets.Assets.Text = i .. "/" .. #Assets
bar.Size = UDim2.new(progress, 0, 0.111, 0)
end
rotation:Cancel()
(I obviously added more to the last code so now it checks queue size before loading assets but yea)
Preloading already loaded assets won’t yield, so the
if not game:IsLoaded() then
game.Loaded:Wait()
end
waits for all the assets of the game to load, like I said in my first reply. Preloading the already loaded workspace is just asking to preload something that’s already loaded.