[Help] Assets are being deleted after the loading screen ends
Hello everyone,
I’m working on a custom loading screen that preloads assets before transitioning to the main menu. However, I’ve encountered an issue: once the loading finishes and the game moves to the main menu, all assets in the client begin to get destroyed.
Setup
- The LocalScript is placed inside
ReplicatedFirst
to handle the loading process. - It clones the loading screen UI (
ScreenLoadPlaying
) fromReplicatedStorage
, displays it inPlayerGui
, and starts preloading assets fromworkspace
usingContentProvider:PreloadAsync()
. - After loading, the script destroys the loading screen and enables the Main Menu UI (
MainMenu
). - The Main Menu LocalScript moves the camera to a new position.
Issue
Everything works fine until the loading process ends. When the EndLoad()
function is called, the game transitions to the Main Menu, but all assets in the client start disappearing.
Code (LocalScript in ReplicatedFirst)
-- Services
local player = game:GetService("Players").LocalPlayer
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")
local ContentProvider = game:GetService("ContentProvider")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Global Variables
local UIS = {}
local isLoad = true
local usedTipsIndices = {}
local lastTipUpdateTime = 0
local tipInterval = 10
-- Player Instances
local PlayerGui = player.PlayerGui
-- Instances
local ScreenLoad = ReplicatedStorage:WaitForChild("GUI"):WaitForChild("ScreensLoad"):WaitForChild("ScreenLoadPlaying"):Clone()
ScreenLoad.Parent = PlayerGui
local loadingRing = ScreenLoad:WaitForChild("Content"):WaitForChild("Loader")
local Assets = workspace:GetDescendants()
-- Events
local FinishLoadEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Player"):WaitForChild("ScreenLoad"):WaitForChild("FinishLoad")
-- Modules
local ScreenLoadModule = require(ReplicatedFirst.Modules.ScreenLoad)
FinishLoadEvent.Event:Connect(function(state)
EndLoad(state)
end)
function StartLoad()
for _, child in pairs(PlayerGui:GetChildren()) do
if child.Enabled then
child.Enabled = false
table.insert(UIS, child)
end
end
UserInputService.MouseIconEnabled = true
ScreenLoad.Enabled = true
ReplicatedFirst:RemoveDefaultLoadingScreen()
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)
local tween = TweenService:Create(loadingRing, tweenInfo, {Rotation = 360})
tween:Play()
Load()
end
function Load()
local totalAssets = #Assets
for i, asset in ipairs(Assets) do
if not isLoad then return end
local percentageLoaded = math.round(i / totalAssets * 100)
ContentProvider:PreloadAsync({asset})
ScreenLoad.Content.Loader.load.Text = percentageLoaded .. "%"
if tick() - lastTipUpdateTime >= tipInterval then
ScreenLoad.Content.Tip.Text = GetUniqueRandomTip()
lastTipUpdateTime = tick()
end
if i % 200 == 0 then
task.wait()
end
end
EndLoad(false)
end
function EndLoad(isEvent)
isLoad = false
task.wait(0.1)
ScreenLoad.Content.state.Text = isEvent and "Assets loaded successfully!" or "Assets skipped successfully!"
task.wait(0.8)
for _, child in pairs(UIS) do
child.Enabled = true
end
ScreenLoad:Destroy()
player:WaitForChild("PlayerScripts"):WaitForChild("MainMenu"):WaitForChild("MainMenu").Enabled = true
end
StartLoad()
Expected Behavior
- The loading screen should preload assets and update the UI accordingly.
- Once finished, it should transition to the main menu without affecting any assets.
Actual Behavior
- The assets start getting destroyed after transitioning to the main menu.
Additional Information
-
Here’s a video showing the issue: Streamable Link
-
The
ScreenLoadPlaying
UI is stored insideReplicatedStorage: GUI -> ScreensLoad -> ScreenLoadPlaying
. -
The
MainMenu
script correctly enables the main menu UI and moves the camera, but the assets still disappear.
Has anyone experienced this issue before? Any ideas on what might be causing the assets to be removed?
Any help would be greatly appreciated! Thanks in advance.