Game Descendants not properly loading

This is my first post, so sorry if I’m not doing it correctly.

I used the following script shown below to add a loading screen to my game, where it loads all of the game’s descendants before letting the player play the game. Whenever I test it in studio, it works fine, however when I play the game live, it always freezes at game.Players.

I’ve had other people try my game live and it always freezes for them at the same as well, leading me to believe that, y’know, it’s either an issue with Roblox or my game scripting being dumb. Either way, I wanted to ask if there are any issues with the code.

There aren’t really any solutions I’ve found so far, I’ve looked in a bunch of spots on the DevForum and can’t seem to find anything.

-- SERVICES
local CTP = game:GetService("ContentProvider")
local RF = game:GetService("ReplicatedFirst")
local TS = game:GetService("TweenService")
local P = game:GetService("Players")

-- VARIABLES
local player = P.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local loading = script:WaitForChild("LoadingGui")

local splash = {"This is just a big chunk of strings modified in the post, not important to the script"}

RF:RemoveDefaultLoadingScreen()

local assets = game:GetDescendants()
local cloned = loading:Clone()
cloned.Parent = playerGui
cloned.Line.Fill.Size = UDim2.fromScale(0, 1)

for i = 1, #assets do
	local asset = assets[i]
	print(asset) -- Find where the game stops loading
	local percent = math.round(i / #assets * 100)
	
	local random = math.random(1, 250)
	if random == 250 then
		cloned.Line.Title.Text = splash[math.random(1, #splash)] .. "..."
	end
	
	CTP:PreloadAsync({asset})
	cloned.Line.Percentage.Text = percent .. "%"
	cloned.Line.Assets.Text = i .. " / " .. #assets
	
	TS:Create(cloned.Line.Fill, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percent/100, 1)}):Play()
	
	if i % 5 == 0 then
		task.wait()
	end
	
	if i == #assets then
		cloned.Line.Title.Text = "FINISHED LOADING"
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		workspace.CurrentCamera.CFrame = workspace.MenuCamera.CFrame
		task.wait(1)

-- Fire an event that is returned to the player in a ServerScript to tell them that the game's actually loaded
		game:GetService("ReplicatedStorage").MenuSelect:FireServer(player)
	end
end

(The script above is called “Main” in ReplicatedFirst)
image

Seems to be an issue with other parts of the game, I’ve band-aid fixed it for now by just removing the custom loading screen.

Perhaps you could try and exclude the players category from loading?

-- SERVICES
local CTP = game:GetService("ContentProvider")
local RF = game:GetService("ReplicatedFirst")
local TS = game:GetService("TweenService")
local P = game:GetService("Players")

-- VARIABLES
local player = P.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local loading = script:WaitForChild("LoadingGui")

local splash = {"This is just a big chunk of strings modified in the post, not important to the script"}

RF:RemoveDefaultLoadingScreen()

local assets = game:GetDescendants()
local cloned = loading:Clone()
cloned.Parent = playerGui
cloned.Line.Fill.Size = UDim2.fromScale(0, 1)

for i = 1, #assets do
	local asset = assets[i]
        if asset.Parent ~= game.Players then
print(asset) -- Find where the game stops loading
	local percent = math.round(i / #assets * 100)
	
	local random = math.random(1, 250)
	if random == 250 then
		cloned.Line.Title.Text = splash[math.random(1, #splash)] .. "..."
	end
	
	CTP:PreloadAsync({asset})
	cloned.Line.Percentage.Text = percent .. "%"
	cloned.Line.Assets.Text = i .. " / " .. #assets
	
	TS:Create(cloned.Line.Fill, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percent/100, 1)}):Play()
	
	if i % 5 == 0 then
		task.wait()
	end
	
	if i == #assets then
		cloned.Line.Title.Text = "FINISHED LOADING"
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		workspace.CurrentCamera.CFrame = workspace.MenuCamera.CFrame
		task.wait(1)

-- Fire an event that is returned to the player in a ServerScript to tell them that the game's actually loaded
		game:GetService("ReplicatedStorage").MenuSelect:FireServer(player)
	end
        end
end