Can't get custom loading screen to work... Keeps getting a error everytime I fix the previous one

I’ve been trying to make a custom loading screen for one of my upcoming games but it keeps on getting errors again & again. I have tried asking the AI assistant to re-write the script and have completly sourced the entire script from the developer documentation.

So Basically Whenever i change the value of both the MainLoader & The MainMenu to script.parent.parent(as in the code below) from game.StarterGUI.MainLoader/MainUI) the LoadingBar(TweenService) Doesn’t work. However, when I keep atleast on of them as game.StarterGUI.MainLoader/MainUI the tween service works. For example:

The tweenservice works with these values:

local MainMenus = script.Parent.Parent.Parent.Parent.MainUI
local MainLoader = game.StarterGUI.MainLoader
local MainMenus = game.StarterGUI.MainUI
local MainLoader = script.Parent.Parent.Parent
local MainMenus = game.StarterGUI.MainUI
local MainLoader = game.StarterGUI.MainLoader

But it doesnt work with:

local MainMenus = script.Parent.Parent.Parent.Parent.MainUI
local MainLoader = script.Parent.Parent.Parent

Here’s the code:

local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
local TweenService = game:GetService("TweenService")
local Background = script.Parent
local UIS = game:GetService("UserInputService")
local GUIService = game:GetService("GuiService")
local MainMenus = script.Parent.Parent.Parent.Parent.MainUI
local MainLoader = script.Parent.Parent.Parent
local LDecal = script.Parent.Parent.Loader

ReplicatedFirst:RemoveDefaultLoadingScreen()
local assets = game.Workspace:GetDescendants()
MainLoader.Enabled = true
	
for i = 1, #assets do
	local asset = assets[i]
	local percentage = math.floor(i / #assets * 100)
	ContentProvider:PreloadAsync({asset})
	Background:WaitForChild("AssetsLoaded").Text = "Loading Assets: "..i.." of "..#assets.." ("..percentage.."%)"
	TweenService:Create(Background.LoadingBar.Bar, TweenInfo.new(0.2,Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(percentage/100, 1)}):Play()
	if i % 25 == 0 then
		task.wait()
	end
	if i % 50 == 0 then
		task.wait()
	end
	if i % 75 == 0 then
		task.wait()
	end
	if i % 97 == 0 then
		task.wait()
	end
end
wait()
Background:WaitForChild("AssetsLoaded").Text = "Loading Complete!"
task.wait(3)
MainMenus.Enabled = true
task.wait(1)
LDecal.Visible = true
task.wait(5)
MainLoader.Enabled = false

Here’s a SS of the explorer if it might help(refer to the Handler script under MainFrame)
image

Been trying to figure it out since some time but couldnt find any errors… tried searching for it but nothing came up. Any help will be appriciated, Thanks.

Here is a suggestion. Create a localscript, parent it to ReplicatedFirst, and put your code into there, as well as the loading screen assets parented to it.

Also, is there any specific issues, for example loading screen not showing up, loading bar pausing, and etc.?

Stop using StarterGui for the UI. It isn’t modifying the players gui (located within LocalPlayer.PlayerGui when in client).
This is because it is referencing the incorrect object.
image
Just use parent statements instead.

1 Like

These don’t actually work either, they just don’t throw an error.

You have to get the PlayerGui of the player. You can do so by using either FindFirstAncestor("PlayerGui") or by getting game.Players.LocalPlayer.PlayerGui.

Also, don’t try asking the AI assistant, it usually just makes your code worse.