Why repeat task.wait() until game:IsLoaded() bug? in roblox studio

i used someone script on loading screen and line 20 is bug and cause all the function not starting. what should i use instead of repeat task.wait() until game:IsLoaded().

local player = game:GetService("Players")
local players = player.LocalPlayer
local playerGui = players:WaitForChild("PlayerGui")

local tweenService = game:GetService("TweenService")
local repFirst = game:GetService("ReplicatedFirst")
local contentProvider = game:GetService("ContentProvider")

local menuGui = script:WaitForChild("LoadingGui")

repFirst:RemoveDefaultLoadingScreen()

local assets = game:GetDescendants()

local clonedGui = menuGui:Clone()
clonedGui.Parent = playerGui

tweenService:Create(clonedGui.Background:WaitForChild("Logo"), TweenInfo.new(.6, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {Position = UDim2.fromScale(clonedGui.Background:WaitForChild("Logo").Position.X.Scale, clonedGui.Background:WaitForChild("Logo").Position.Y.Scale + 0.02)}):Play()

repeat task.wait() until game:IsLoaded()

for i = 1, #assets do
	local asset = assets[i]
	local percentage = math.round(i/#assets * 100)
	contentProvider:PreloadAsync({asset})
	
	clonedGui.Background:WaitForChild("Percentage").Text = percentage.."%"
	clonedGui.Background:WaitForChild("Loaded").Text = "Loading Assets : "..i.."/"..#assets
	
	tweenService:Create(clonedGui.Background.BarGround:WaitForChild("Bar"), TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percentage/100, 1)}):Play()
	
	if i % 1 == 0 then
		task.wait()
	end
	if i == #assets then
		task.wait(1)
	end
end

for i, v in pairs(clonedGui:GetDescendants()) do
	if v:IsA("Frame") then
		tweenService:Create(v, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
	elseif v:IsA("TextLabel") then
		tweenService:Create(v, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
	end
	if v:IsA("ImageLabel") then
		tweenService:Create(v, TweenInfo.new(0.5), {ImageTransparency = 1, BackgroundTransparency = 1}):Play()
	elseif v:IsA("UIStroke") then
		tweenService:Create(v, TweenInfo.new(0.5), {Thickness = 0}):Play()
	end
end

You can just do game.Loaded:Wait().

Incase the game is lightning fast at loading you can do this to prevent any problems, mainly the game loading before that line runs:

if not game:IsLoaded() then
    game.Loaded:Wait()
end
4 Likes

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