Hello guys, I am trying to make a LocalScript that will delete all GUis in a player's PlayerGUi folder except for some that have a certain name. The issue is I keep getting :Destroy() is a nil value because I am using GetChildren which gets it a table and apparently Destroy does not work with tables?
Here is my script
local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:WaitForChild("Died")
local player = game.Players.LocalPlayer
event.OnClientEvent:connect(function()
if player.PlayerGui:GetChildren().Name ~= "Shop" then
player.PlayerGui:GetChildren():Destroy()
end
end)
Now I have made a post similar to this before, and the solution was to do something like this,
local guis = player.PlayerGui:GetChildren()
for _, v in pairs(guis) do
if v.Name ~= "Shop" then
v:Destroy()
end
end
However, this time I am in a LocalScript...would it be silly or bad practice to do for _, v in pairs in a LocalScript?

2 comments
If you have FE enabled, you'll need a remote event to do the for loop from the server.
https://scriptinghelpers.org/blog/common-mistakes#GetChildren