How can I put stuff on my loading screen and dynamically change something on it

I plan to add a loading screen, and onto that loading screen i plan to add super edgy quotes (that I took from GPT)

but i’ve never made a loading screen before, how can i dynamically change text on a loading screen?

is it something like;

-- this here is pure pseudocode

while game is loading do
   switch text
   task.wait(10)
end
if not game.IsLoaded then
repeat
wait(10)
*switch text*
until game.IsLoaded
end

i’ll try this in a minute and let you know, hold on

okay so i ended up finding out about the existence of ContentProvider

though i’m not sure whether i did something wrong, because the game seems to load for pretty long

local contentProvider = game:GetService("ContentProvider")
local ui = script:WaitForChild("LoadingScreen"):Clone()

local assets = game:GetDescendants()

local plr = game:GetService("Players").LocalPlayer
local plrGui = plr.PlayerGui

ui.Parent = plrGui

local quotes = ui:WaitForChild("Quotes")

local quoteChances = {
	["I rebel, therefore I exist."] = 10,
	["Question everything."] = 10,
	["Live fast, die young."] = 10,
	["We are all mad here."] = 10,
	["I am the storm."] = 10,
	["Normal is boring."] = 10,
	["Reality is a prison."] = 10,
	["Die with memories, not dreams."] = 10,
	["Embrace the chaos."] = 10,
	["Silence is the loudest scream."] = 10
}

function SelectQuote()
	local totalChance = 0
	for _,chance in quoteChances do
		totalChance += chance
	end

	local rng = math.random(1,totalChance)

	for quote, chance in quoteChances do
		rng -= chance
		if rng <= 0 then
			return quote
		end
	end
end

if not game:IsLoaded() then
	plr:SetAttribute("Loaded", false)
	
	repeat
		quotes.Text = SelectQuote()
		task.wait(5)
	until contentProvider:PreloadAsync(assets)
end

task.wait(1)

plr:SetAttribute("Loaded", true)
ui:Destroy()

Does it print any errors or warnings? Try to see it
If not, reply back so I can show a script i provide

mmm, no

but i ended up doing something like this

if not game:IsLoaded() then
	plr:SetAttribute("Loaded", false)

	coroutine.wrap(function()
		while not game:IsLoaded() do
			quotes.Text = SelectQuote()
			task.wait(5)
		end
	end)()

	local success, err = pcall(function()
		contentProvider:PreloadAsync(assets)
	end)

	if not success then
		warn("Failed to preload asset: " .. err)
	end
end

idk if this is the most optimal way, but it works

So is it solved?

I found another way too

if not game:IsLoaded() then
	plr:SetAttribute("Loaded", false)

	for i = 1, #assets do
		local asset = assets[i]
		ContentProvider:PreloadAsync({asset})
	end
end
1 Like

it is solved yeah

i’ll mark my response as solution since it works

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