Freezing when using PreloadAsset

This occasionally happens whenever I use the script located below.
https://gyazo.com/03ba358bf9b9ff6b3f9932ffe4d288eb (I’m clicking every button possible)

script.Parent.Enabled = true
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat,false)
if not game.Loaded then
	game.Loaded:Wait()
end
if game:GetService("RunService"):IsStudio() then script.Parent.Enabled = false return end


local tips = {
	"You can click the spoon of the Cauldron to mix the contents!";
	"You can click on your chests to access it's contents!";
	"Some spells can't be stacked, such as being ignited twice. Use this to your advantage!";
	"Leaving the game outside of a safe zone drops your soul for one minute, allowing others to claim it and take your items.";
}

loadTips = true

spawn(function()
	while loadTips do
		game:GetService("TweenService"):Create(script.Parent.BG.TipText,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{TextTransparency = 1}):Play()
		wait(1)
		local newTip = tips[math.random(1,#tips)]
		while "<i>TIP: "..newTip.."</i>" == script.Parent.BG.TipText.Text do
			local newTip = tips[math.random(1,#tips)]
		end
		script.Parent.BG.TipText.Text = "<i>TIP: "..newTip.."</i>"
		game:GetService("TweenService"):Create(script.Parent.BG.TipText,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 0}):Play()
		task.wait(6.5)
	end
end)


local assetsTable = game.Workspace:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

script.Parent.Enabled = true

for i = 1, totalAssets do
	local suc,ero = pcall(function()
		game:GetService("ContentProvider"):PreloadAsync({assetsTable[i]})
		assetsLoaded = i
		script.Parent.BG.BarBack.BarFront.Size = UDim2.new(i/totalAssets, 0, 1, 0)
		script.Parent.BG.Progress.Text = i.."/"..totalAssets
		script.Parent.BG.Percent.Text = math.floor((i/totalAssets)*100).."%"
	end)
	if not suc then warn(ero) end
end

loadTips = false
script.Parent.BG.LoadingText.Text = "Loaded!"
game:GetService("TweenService"):Create(script.Parent.BG.TipText,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{TextTransparency = 1}):Play()
wait(1)
script.Parent.BG.TipText.Text = "<i>TIP: Have fun!</i>"
game:GetService("TweenService"):Create(script.Parent.BG.TipText,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 0}):Play()
wait(1)

game.Workspace.Map.SpawnLocation.Position = Vector3.new(-175.247, 120, -642.464)
print(game.Workspace.Map.SpawnLocation.Position)
wait()
game:GetService("ReplicatedStorage").Events.PlayerLoaded:FireServer()

wait(2)


game:GetService("TweenService"):Create(script.Parent.BG.BarBack,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency = 1}):Play()
game:GetService("TweenService"):Create(script.Parent.BG.BarBack.BarFront,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency = 1}):Play()
game:GetService("TweenService"):Create(script.Parent.BG.LoadingText,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 1}):Play()
game:GetService("TweenService"):Create(script.Parent.BG.TipText,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 1}):Play()
game:GetService("TweenService"):Create(script.Parent.BG.Percent,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 1}):Play()
game:GetService("TweenService"):Create(script.Parent.BG.Progress,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{TextTransparency = 1}):Play()

game:GetService("TweenService"):Create(script.Parent.BG.Logo,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Position = UDim2.new(.5,0,.545,0)}):Play()
wait(4.5)
game:GetService("TweenService"):Create(script.Parent.BG.Logo,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{ImageTransparency = 1}):Play()
wait(.1)
game:GetService("TweenService"):Create(script.Parent.BG,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{BackgroundTransparency = 1}):Play()
wait(3)
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat,true)
script.Parent:Destroy()

Any ideas? Cheers!

1 Like

Still haven’t found a solution. Anyone have any idea?

1 Like

Have you used prints to try and debug where exactly it is yielding, because so far I am lost on where the problem may be. Are you sure its the PreloadAsync function?

Prints do not help, the game freezes before I can see what’s printed on the console. I’m not entirely sure if it’s the PreloadAsync, but I suspect it could be.