Loading screen not working

Hi, I’ve been creating a simple loading screen, yet it breaks and it’s frustrating me.
image

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")

local Queue

ReplicatedFirst:RemoveDefaultLoadingScreen()

local LoadingUI = script:WaitForChild("Descendants").UI.LoadingUI:Clone()
LoadingUI.Parent = Player.PlayerGui

while task.wait() do
	local s, e = pcall(function()
		Queue = ContentProvider.RequestQueueSize
	end)
	if not s then warn(e) end
	if s then Queue = Queue else warn(e) end
	if Queue == 0 then
		repeat task.wait() until LoadingUI:WaitForChild("Loading")
		repeat
			LoadingUI.Loading.BackgroundTransparency += 0.01
			LoadingUI.Loading.Logo.ImageTransparency += 0.01
			task.wait(0.01)
		until LoadingUI.Loading.BackgroundTransparency >= 1 and LoadingUI.Loading.Logo.ImageTransparency >= 1
		if LoadingUI.Loading.BackgroundTransparency >= 1 and LoadingUI.Loading.Logo.ImageTransparency >= 1 then
			LoadingUI:Destroy()
			script:Destroy()
		end
	end
end

It’s a very simple script and yet it can’t just do the repeat loop without it breaking.
PS this half works in studio and breaks in-game

Anybody knows? :slight_smile: