:PreloadAsync()

So, I not really sure it’s a bug or what. I used a normal script which load the asset [I used get children because I don’t want it load too much]

local ReplicatedFirst = game:GetService(“ReplicatedFirst”)
local ContentProvider = game:GetService(“ContentProvider”)
local TweenService = game:GetService(“TweenService”)
local Player = game:GetService(“Players”).LocalPlayer

local Main = script.Parent:WaitForChild(“Main”)
local Holder = Main:WaitForChild(“Holder”)

ReplicatedFirst:RemoveDefaultLoadingScreen()

local Assets = game:GetChildren()

for i = 1, #Assets do
local Asset = Assets[i]
local Percentage = math.round(i/#Assets * 100)

ContentProvider:PreloadAsync({Asset})

Holder.AssetsLoaded.Text = "Loading Assets ("..i.."/"..#Assets..")"

TweenService:Create(Holder.Bar, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.fromScale(Percentage/100, 1)}):Play()

if i % 25 == 0 then
	wait()
end

if i == #Assets then
	wait(1)
end

end

local OutTI = TweenInfo.new(1, Enum.EasingStyle.Quint)

Main.TextButton.Visible = false
script.Parent.Effects1:Destroy()
script.Parent.Effects2:Destroy()
script.Parent.Effects3:Destroy()
TweenService:Create(script.Parent.Main, OutTI, {BackgroundTransparency = 1}):Play()
for i, ui in pairs(Main:GetChildren()) do
if ui.ClassName == “Frame” then
TweenService:Create(ui.Bar, OutTI, {BackgroundTransparency = 1}):Play()
TweenService:Create(ui.Anim, OutTI, {BackgroundTransparency = 1}):Play()
TweenService:Create(ui.AssetsLoaded, OutTI, {TextTransparency = 1}):Play()

elseif ui.ClassName == "TextLabel" then
	TweenService:Create(ui, OutTI, {TextTransparency = 1}):Play()
	
elseif ui.ClassName == "ImageLabel" then
	TweenService:Create(ui, OutTI, {ImageTransparency = 1}):Play()
end


if ui:FindFirstChildWhichIsA("UIStroke") then
	local Stroke = ui:FindFirstChildWhichIsA("UIStroke")
	
	TweenService:Create(Stroke, OutTI, {Transparency = 1}):Play()
end
task.wait(0.1)
script.Parent.Parent.Intro.Enabled = true
script.Parent.Enabled = false

end

But the thing is, It stuck at 24/102. Like stuck forever. Anyone knows how to fix it?

1 Like

Here is the fixed code format (not the answer):

local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer

local Main = script.Parent:WaitForChild("Main")
local Holder = Main:WaitForChild("Holder")

ReplicatedFirst:RemoveDefaultLoadingScreen()

local Assets = game:GetChildren()

local formatString = "Loading Assets (%i/%i)"

for i, Asset in ipairs(Assets) do
	local Percentage = math.floor(i/#Assets * 100)
	ContentProvider:PreloadAsync({Asset})
	
	Holder.AssetsLoaded.Text = formatString:format(i, #Assets)
	
	TweenService:Create(Holder.Bar, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.fromScale(Percentage/100, 1)}):Play()
	
	if i % 25 == 0 then
		task.wait()
	end
	
	if i == #Assets then
		task.wait(1)
	end
end

local OutTI = TweenInfo.new(1, Enum.EasingStyle.Quint)

Main.TextButton.Visible = false
script.Parent.Effects1:Destroy()
script.Parent.Effects2:Destroy()
script.Parent.Effects3:Destroy()
TweenService:Create(script.Parent.Main, OutTI, {BackgroundTransparency = 1}):Play()

for i, ui in pairs(Main:GetChildren()) do
	if ui.ClassName == "Frame" then
		TweenService:Create(ui.Bar, OutTI, {BackgroundTransparency = 1}):Play()
		TweenService:Create(ui.Anim, OutTI, {BackgroundTransparency = 1}):Play()
		TweenService:Create(ui.AssetsLoaded, OutTI, {TextTransparency = 1}):Play()
	elseif ui.ClassName == "TextLabel" then
		TweenService:Create(ui, OutTI, {TextTransparency = 1}):Play()
		
	elseif ui.ClassName == "ImageLabel" then
		TweenService:Create(ui, OutTI, {ImageTransparency = 1}):Play()
	end

	if ui:FindFirstChildWhichIsA("UIStroke") then
		local Stroke = ui:FindFirstChildWhichIsA("UIStroke")
		
		TweenService:Create(Stroke, OutTI, {Transparency = 1}):Play()
	end
	
	task.wait(0.1)
	script.Parent.Parent.Intro.Enabled = true
	script.Parent.Enabled = false
end
1 Like

try wrapping ContentProvider:PreloadAsync() into a pcall

pcall(ContentProvider.PreloadAsync, ContentProvider, {Asset})

wrapping the functions avoids errors that might stop the execution of the script which makes it stuck at 24/102

answer:

local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer

local Main = script.Parent:WaitForChild("Main")
local Holder = Main:WaitForChild("Holder")

ReplicatedFirst:RemoveDefaultLoadingScreen()

local Assets = game:GetChildren()

local formatString = "Loading Assets (%i/%i)"

for i, Asset in ipairs(Assets) do
	local Percentage = math.floor(i/#Assets * 100)
	pcall(ContentProvider.PreloadAsync, ContentProvider, {Asset})
	
	Holder.AssetsLoaded.Text = formatString:format(i, #Assets)
	
	TweenService:Create(Holder.Bar, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.fromScale(Percentage/100, 1)}):Play()
	
	if i % 25 == 0 then
		task.wait()
	end
	
	if i == #Assets then
		task.wait(1)
	end
end

local OutTI = TweenInfo.new(1, Enum.EasingStyle.Quint)

Main.TextButton.Visible = false
script.Parent.Effects1:Destroy()
script.Parent.Effects2:Destroy()
script.Parent.Effects3:Destroy()
TweenService:Create(script.Parent.Main, OutTI, {BackgroundTransparency = 1}):Play()

for i, ui in pairs(Main:GetChildren()) do
	if ui.ClassName == "Frame" then
		TweenService:Create(ui.Bar, OutTI, {BackgroundTransparency = 1}):Play()
		TweenService:Create(ui.Anim, OutTI, {BackgroundTransparency = 1}):Play()
		TweenService:Create(ui.AssetsLoaded, OutTI, {TextTransparency = 1}):Play()
	elseif ui.ClassName == "TextLabel" then
		TweenService:Create(ui, OutTI, {TextTransparency = 1}):Play()
		
	elseif ui.ClassName == "ImageLabel" then
		TweenService:Create(ui, OutTI, {ImageTransparency = 1}):Play()
	end

	if ui:FindFirstChildWhichIsA("UIStroke") then
		local Stroke = ui:FindFirstChildWhichIsA("UIStroke")
		
		TweenService:Create(Stroke, OutTI, {Transparency = 1}):Play()
	end
	
	task.wait(0.1)
	script.Parent.Parent.Intro.Enabled = true
	script.Parent.Enabled = false
end

Not working. But anyways I found the solution

I found out that the reason it stuck is because the new player so I make it exempt the stuff that parent has humanoid in it

1 Like

Mark this as the solution for you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.