i want to make a loading screen for my game but i don’t know how. this is what i have so far:
local gui = script:WaitForChild("Loading"):Clone()
local content = game:GetService("ContentProvider")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
ReplicatedFirst:RemoveDefaultLoadingScreen()
local plr = game.Players.LocalPlayer
local plrgui = plr.PlayerGui
script.Loading.LoadingScreen.Visible = true
gui.Parent = plrgui
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if not game:IsLoaded() then
game.Loaded:Wait()
Humanoid.WalkSpeed = 0
HumanoidRootPart.Anchored = true
else
Humanoid.WalkSpeed = 16
HumanoidRootPart.Anchored = false
plrgui.Loading:Destroy()
end
for i = 1, #assets do
local asset = assets[i]
content:PreloadAsync({asset})
gui:WaitForChild("LoadingScreen"):WaitForChild("LoadStatus").Text = "Loading: " ..asset.Name.. " [" .. i .. "/" .. #assets .. "]"
end
this script is in replicated storage alongside with the loading screen itself.
this game is a single player horror game. my loading screen is basic, just black background with the asset loading name.
Using your code as a start, but one critique. By the time the first asset is loaded, my progress meter is already at 900/2900. Have you messed around with coroutines to make the counter start at 1? I don’t want people sitting around for a minute wondering what happened (they have a slow machine).
I’ll give this a try, but curious if you have had this issue.
local loadCount = 0
for i = 1, #assets do
coroutine.wrap(function ()
local asset = assets[i]
contentprovider:PreloadAsync({asset})
loadCount += 1
loadStatus.Text = "Loading: " ..asset.ClassName .. " [" .. loadCount .. "/" .. #assets .. "]"
end)()
end
repeat task.wait() until #assets == loadCount
The count started at 2930, not 900, as almost all the assets loaded immediately. I don’t know if that is good or bad. Also, I got a record gameload time. That certainly wasn’t intentional! I could also see that the slowest loading asset is the StarterGUI, so I might be able to improve that even more.
Anyway, dropped some code in here for anyone looking for solutions! Thanks again!