Constantly checking if "skipClicked" is true whilst assets are being loaded?

Like the title says – In this case, is there anyway to constantly check if skipClicked is true while the assets are loading?

I’ve made a checker for if the player skips the assets, but the issue arises of the player not having enough time to set skipClicked to false, meaning that it’ll continue on with the while loop in most cases. So if the players click skiploadingbutton whilst it reaches the point where it loads the assets, they have to wait for the assets to load. Is there any solution to this?

local skipClicked = false
local isLoading = false

skiploadingbutton.MouseButton1Click:Connect(function()
	skipClicked = true
	sound:Play()
end)



local assets = game:GetDescendants()
local ContentProvider = game:GetService("ContentProvider")
local loadingAssets = true

while loadingAssets do
	if skipClicked then
		print("Assets skipped!")
		loadingAssets = false
		isLoading = false
		break
	end

	if not skipClicked then
		isLoading = ContentProvider:PreloadAsync(assets)
	end	

	if not isLoading then
		loadingAssets = false
		print("Assets loaded!")
	end
	task.wait()
end

Loop through the assets table, Preloading each thing individually.

for i,v in pairs(assets) do
	if not skipClicked then
		ContentProvider:PreloadAsync({v})
		print(`currently loaded {i}/{#assets}!`)
	else
		print("Assets skipped")
		break
	end
end

print("Assets loaded/skipped!")

This’ll also allow you to see how much stuff has currently loaded

1 Like

Just chiming in, preloading is typically used to load in important assets beforehand, such as essential UI images, like start menus, or sounds. Loading all the descendants of the game is what ROBLOX already does, and will make your loading screen very long if you preload all of them.

1 Like

Worked like a charm, thank you (feeling kinda dumb now for not thinking of that)

Never knew that, I’ll keep that noted. Thanks!

So how can I preload the main stuff

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