PreloadAssets sometimes wont work or got stuck at 0%

Title says it all

game:GetService("ReplicatedFirst"):RemoveDefaultLoadingScreen()
local cp = game:GetService("ContentProvider")
local dontPreload = {
	["Lighting"] = false;
	["Workspace"] = false;
	["ServerStorage"] = false;
}

local sTick = tick()

local numPreload = 0
local totalAssset = 0
_G.preloaded = false
game.ReplicatedStorage:WaitForChild("Server").Freeze:FireServer()
game.Players.LocalPlayer.PlayerGui:WaitForChild("LoadingScreen").Enabled = true
game.Players.LocalPlayer.PlayerGui:WaitForChild("LoadingScreen").Frame.TextLabel.LocalScript.Percent.Value = 0

for i,service in pairs(game:GetChildren()) do
	pcall(function()
		if not dontPreload[service.Name] then
			totalAssset = totalAssset + 1
		end
	end)
end

for i,service in pairs(game:GetChildren()) do
	pcall(function()
		if not dontPreload[service.Name] then
			cp:PreloadAsync({service})
			numPreload = numPreload + 1
			game.Players.LocalPlayer.PlayerGui["LoadingScreen"].Frame.TextLabel.LocalScript.Percent.Value = (numPreload/totalAssset)*100
		end
	end)
end
warn("Done, time: "..string.sub(tick()-sTick, 1, 5).."s")
wait(2)
game.ReplicatedStorage.Server.Reset:FireServer()
game.Players.LocalPlayer.PlayerGui.LoadingScreen.Enabled = false
_G.preloaded = true

EDIT:
Preload Animations ONLY. fixes everything since animation will be laggy if you didnt preload them

Honestly, if you’re trying to make a loading screen, I suggest using Game.Loaded and Game:IsLoaded(), sometimes Content Provider may fail you since it forces the script to wait for an http connection, if Roblox has an API issue on that, players will never load into your game.

This is the article for the properties I’ve mentioned.

1 Like