How do I make a script, that deletes any new UI's in the Player's UI, apart from the existing UI's in Startergui?

How do I make a script, that deletes any new UI’s in the Player’s UI, apart from the existing UI’s in Startergui? As a small quality of life thing for me, it’s not really a security measure, because of Filtering Enabled, but yeah.

tried this as a local script (would prefer if it’s serversided though):

local function deleteNonStarterGuiChildren()
    local player = game.Players.LocalPlayer
    local playerGui = player:WaitForChild("PlayerGui")
    local starterGui = game.StarterGui

    while wait(1) do
        for _, child in ipairs(playerGui:GetChildren()) do
            if child:IsA("GuiObject") and not starterGui:FindFirstChild(child.Name) then
                child:Destroy()
            end
        end
    end
end

deleteNonStarterGuiChildren()
1 Like

Try this:

local function deleteNonStarterGuiChildren()
    local player = game.Players.LocalPlayer
    local playerGui = player:WaitForChild("PlayerGui")
    local starterGui = game.StarterGui

    while wait(1) do
        for _, child in ipairs(playerGui:GetChildren()) do
            if child:IsA("ScreenGui") and not starterGui:FindFirstChild(child.Name) then
                child:Destroy()
            end
        end
    end
end
deleteNonStarterGuiChildren()

If I remember correctly, “GuiObject” doesn’t include ScreenGuis. Just frames and textlabels, ImagesLabels etc, with things that Have Position and Visible property, (ScreenGui has Enable and not Visible property )

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.