Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I remove all except for a certain name?

I want to remove all GUIs except those named something, so I am trying this

local playergui = player.PlayerGui:GetChildren()
local values = {player.PlayerGui.Shop.Name, player.PlayerGui.Boom.Name, 	player.PlayerGui.Boom.Name}
	if playergui.Name == values
		print('All is good')
		-- Do nothing
		else
		playergui:remove()
	end

However I am getting, line 22 attempt to call method 'remove' a nil value

2 comments

0

@Thetacah made a reply to another post of mine that is similar, I will try and see if that works. Will report back

0

That did not seem to work, I still have the same error as above.

1 answer

playergui isn't an object -- it's a list of objects. A list doesn't have a .Name, and you can't :Remove() a list.


Here is what you want to do:

For each object in the list playergui, if it's name is not what I'm looking for, Destroy it.

local guis = player.PlayerGui:GetChildren()

for _, gui in pairs(guis) do
	-- for each `gui` in the list `guis` do this:
	if gui.Name == "Shop" or gui.Name == "Boom" then
		print("All is good")
	else
		gui:Destroy()
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.