Sorry about that, was reading too fast. What you need is a function that will search the whole list for a single value. You're iterating over it now but printing every value in guis that doesn't match the child added.
function tableContains(list, find)
for _, listItem in ipairs(list) do
if listItem == find then
return true
end
end
return false
end
local guis = {"ControlGui", "Chat"}
repeat wait() until game.Players
for i,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.ChildAdded:connect(function(child)
if not tableContains(guis, child.Name) then
print(child.Name)
end
end)
end
EDIT:
To remove the unwanted gui, see the updated script below. This will remove the "Chat" gui since it's not in the whitelist.
spawn() is used here to tell Roblox to call child:Destroy() AFTER then code exits the ChildAdded event handler. It will actually execute it on the next wait(). You can't destroy it in the handler because Roblox is still working with it immediately after the handler. So you have to give Roblox a chance to finish with it first, then destroy it.
function tableContains(list, find)
for _, listItem in ipairs(list) do
if listItem == find then
return true
end
end
return false
end
local guis = {"ControlGui"}
repeat wait() until game.Players
for i,v in pairs(game.Players:GetChildren()) do
v.PlayerGui.ChildAdded:connect(function(child)
if not tableContains(guis, child.Name) then
print(child.Name)
spawn(function()
child:Destroy()
end)
end
end)
end
5 comments
Yes sorry, just fixed that, it still print chat though.
I found a problem, possibly. I was testing this out in a local server, and I was still able to insert a gui into my PlayerGui without getting kicked.
You just asked to print the unwanted GUI. I'll edit to add this new request.
It' still allows me to insert the gui in-game, when not on whitelist and it does not destroy it.
Does it give an error? Does the code I posted work for you for the Chat gui?