What do you want to achieve?
I want to be able to disable Roblox’s default system where the UI from the StarterGui loads in.
What is the issue?
I have a code that would preload the UI to PlayerGui, but upon manually loading character in, it duplicates the UI to PlayerGui. I’ve disabled the auto spawn feature which requires me to load some UI to the player PlayerGui.
What solutions have you tried so far?
I could delete the old UI once I load character, but this will eventually flood my code and it’d be a hassle to manage once I have more UI being added.
Duplicate UI are shown when I manually load character in
I have an idea of what you can do. Turn off all scripts in the user interface, let the script load them in advance and turn them on from script to avoid unexpected errors when a duplicate appears. Set each new element that is loaded by your script to an attribute or tag and create the following function:
-- StarterPlayerScripts
local CollectionService = game:GetService("CollectionService")
local PlayerGui = script.Parent.Parent.PlayerGui
PlayerGui.DescendantAdded:Connect(function(Descendant)
-- Example 1
if not CollectionService:HasTag(Descendant, "TagName") then
Descendant:Destroy()
end
-- Example 2
if not Descendant:HasTag("TagName") then
Descendant:Destroy()
end
-- Example 3
if typeof(Descendant:GetAttribute("AttributeName")) == "nil" then
Descendant:Destroy()
end
end)