How to run a function only when game is fully loaded?

Hi. I’ve asked a few of my friends for help and they couldn’t find the answer so I’m here in devforums now to ask. My issue is that when I run the script it runs the second I press play, and it’s not until 3 - 5 seconds later that the game actually fully loads, so the script is done running by then and I can’t debug it. How would I run the script only if the game is fully loaded (like the gray ish loading screen with the game icon in the middle of the screen)

local function functionToRunWhenTheGameFullyLoads()
	print(true)
end
while not game:IsLoaded() do
	task.wait()
end
functionToRunWhenTheGameFullyLoads()
3 Likes