Recently, I have been working on a loading screen.
The script and everything works fine, but it has come to my attention that it isn’t really loading and it waits an extra 7 ish minutes despite all the other assets having been loaded. Any ideas on how to fix this?
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
repeat task.wait() until workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace:WaitForChild("CamPart").CFrame
wait()
local function resetCameraSubject()
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
repeat task.wait() until workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Follow
Camera.CameraSubject = Player.Character.Humanoid
wait()
end
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Background = script.Parent:WaitForChild("Background")
local guiShown = game:GetService("TweenService"):Create(game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("LoadingScreen"):WaitForChild("Background"):WaitForChild("GameTitle"), TweenInfo.new(1.5, Enum.EasingStyle.Back), {Position = UDim2.new(0.5,0,0.35,0)})
guiShown:Play()
local skipshown = game:GetService("TweenService"):Create(game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("LoadingScreen"):WaitForChild("Background"):WaitForChild("ImageButton"), TweenInfo.new(1.5, Enum.EasingStyle.Back), {Position = UDim2.new(0.5,0,0.74)})
skipshown:Play()
ReplicatedFirst:RemoveDefaultLoadingScreen()
local assets = game.Workspace:GetDescendants()
script.Parent.Enabled = true
for i = 1, #assets do
local asset = assets[i]
local percentage = math.round(i / #assets * 100)
ContentProvider:PreloadAsync({asset})
Background:WaitForChild("DisplayPercentage").Text = percentage.."%"
Background:WaitForChild("AssetsLoaded").Text = "Loading Assets: "..i.."/"..#assets
TweenService:Create(Background.BarBackground.Bar, TweenInfo.new(0.2,Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percentage/100, 1)}):Play()
if i % 50 == 0 then
task.wait()
end
end
Background:WaitForChild("AssetsLoaded").Text = "Game loaded!"
resetCameraSubject()
for i, v in pairs(script.Parent: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()
elseif v:IsA("ImageButton") then
TweenService:Create(v, TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
elseif v:IsA("ImageLabel") then
TweenService:Create(v, TweenInfo.new(0.5), {ImageTransparency = 1}):Play()
end
end
wait(1)
script.Parent.Enabled = false