I am a VERY new scripter, but I wanted to make an introduction GUI for my game. After digging around YouTube, I found absolutely no help whatsoever, so I turned to good old-fashioned “let’s see what I know”.
Turns out, not much. My script is supposed to wait 10 seconds before replacing a “Loading Assets…” title with “Assets Loaded.”, then destroying itself, but it doesn’t seem to be working.
As a naive scripter, I thought this to be the perfect place to get some help.
It worked, but the GUI only stayed for half a second. Do you know how to get around that? Because the script is supposed to make the loading screen stay for 10 seconds, but it doesnt.
See I told you, whenever player is loading while in the loading screen if the time took 10 seconds for that player to load then they will not see any gui at all since its already loaded.
And you can load the important things you wanna load using PreloadAsync
I am confused. The script is supposed to eliminate the default loading screen, then make the custom GUI stay for 10 seconds. I don’t see what you are getting at, could you elaborate further?
@fergusnoot I highly recommend using task.wait instead of wait as it is much more optimized. Also, put it in startergui and see what happens, since replicatedfirst loads really quick, so waiting 10 seconds might not be enough.
And if the GUI appears when you put it in there make it disabled and then enable it via the script.
Like so:
-- Put this after you say what the GUI is.
GUI.Enabled = true
local cp = game:GetService("ContentProvider")
script.Parent:RemoveDefaultLoadingScreen()
local GUI = script.StarterScreen
local CloneGUI = GUI:Clone()
CloneGUI.Parent = game.Players.LocalPlayer.PlayerGui
for i,v in pairs(workspace:GetChildren()) do
cp:PreloadAsync({v})
end
-- once loops ends it will put "Assets loaded" in the counter
CloneGUI.Background.Counter.Text = "Assets Loaded."
wait(1)
CloneGUI:Destroy()
If thats taking too long then put the important things you want to load first in the for loop.
Also, for the 342357th time, you should use task.wait() since it’s more optimized. And instead of straight up destroying the GUI you should tween (animate) it:
-- You can mess around with the parameters
GUI.Background:TweenPosition(UDim2.new(0,0,1,0))
It’s usually a better idea to put it in replicated first, because (as the name suggests) it is created first, being one of the first things to be created, it will also be the first thing the player sees.
Now, this is a pretty good way to make a loading screen. However, sometimes the assets load rather fast, resulting in a short loading screen. For UX sake, you may want to add a custom wait for it to feel more satisfying.
TL;DR:
In short, keep your loading screen in ReplicatedFirst, preload your assets (if desired), and add a short task.wait, all before removing the loading screen.
So, this is pretty confusing, because now I have ended up with this final product of a mess that doesn’t work and I am literally just about to give up. Was my original code correct or incorrect?
CURRENT:
local cp = game:GetService("ContentProvider")
script.Parent:RemoveDefaultLoadingScreen()
local GUI = script.StarterScreen
local CloneGUI = GUI:Clone()
GUI.Enabled = true
CloneGUI.Parent = game.Players.LocalPlayer.PlayerGui
for i,v in pairs(workspace:GetChildren()) do
cp:PreloadAsync({v})
end
-- once loops ends it will put "Assets loaded" in the counter
CloneGUI.Background.Counter.Text = "Assets Loaded."
wait(1)
CloneGUI:Destroy()
Utter confusion, everybody suggesting all these different edits has got me dead in a ditch
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local LoadingLabel = script.Parent.LoadingScreen.LoadingText
local LoadText = script.Parent.LoadingScreen.LoadingNameText
local Loaded = game:IsLoaded() or game.Loaded:Wait()
local ContentProvider = game:GetService('ContentProvider')
if Loaded then
wait(3)
for i,v in pairs(workspace:GetChildren()) do
LoadingLabel.Text = v.Name
ContentProvider:PreloadAsync({v})
wait(.01)
end
end
LoadText.Text = "Loaded!"
wait(2)
script.Parent.LoadingScreen.Parent:Destroy()