How do i make loading faster?

code:

--Services
local replicatedfirst = game:GetService("ReplicatedFirst")
local contentprovider = game:GetService("ContentProvider")
local players = game:GetService("Players")
local ts = game:GetService("TweenService")
local blur = game:GetService("Lighting"):WaitForChild("StartBlur")
--variables
blur.Size = 24
local clock = os.clock()
local assets = game:GetDescendants()
local gui = script:WaitForChild("Loading"):Clone()
local plr = players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local human = plr.Character:WaitForChild("HumanoidRootPart").Anchored
local plrgui = plr:WaitForChild("PlayerGui")
human = true
local ti = TweenInfo.new(10,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out
)
local tg = {Size = 0}
local tc = ts:Create(blur, ti, tg)
--Remove default loading
replicatedfirst:RemoveDefaultLoadingScreen()

--checking if the game loaded
if not game:IsLoaded() then
	game.Loaded:Wait()
end

--parent the loading gui
gui.Parent = plrgui

--Load every game descendants
for i = 1, #assets do
	local asset = assets[i]

	contentprovider:PreloadAsync({asset})
	gui:WaitForChild("Frame"):WaitForChild("LoadStatus").Text = "Loading: " ..asset.Name .. " [" .. i .. "/" .. #assets .. "]"end

--the time it took to load
gui:WaitForChild("Frame"):WaitForChild("LoadStatus").Text = ("Loading complete, took %.2f seconds"):format(os.clock() - clock)
task.wait(3)
gui:Destroy()
human = false
tc:Play()
print ("game loaded")

after i added the blur tween it became over 30 times slower. it used to took around 2 seconds now it takes around 70 seconds.

1 Like

To make loading faster, replace the Lighting:WaitForChild() with FindFirstChild I assume because this is a yielding function it is slowing down the loading times. Unless you dont know for a fact its going to be there, simply do not use WaitForChild but use FindFirstChild, I found this out the hard way in my past experiences.

I hope this helps

now i’m getting another error which is my tween, could you tell me why this is happening?
attempt to index nil with ‘Size’
line:

local tg = {Size = 0}
1 Like

The Size Property is completely correct, which means your script did not find the Blur object successfully, Alternatively, Instead of finding a already created object, we can just create a Blur Object within the loading script. This would eliminate the cause for any searching and just more cleanliness in general.

Example Implementation:

local Lighting = game:GetService("Lighting")
local BlurEffect = Instance.new("BlurEffect")
BlurEffect.Parent = Lighting
BlurEffect.Size = 24

--// From here on continue your normal loading script.
2 Likes

works and it is fast now! char

1 Like