To start off, I properly formatted your code.
local blacklisted_test = {'test1','test2'}
for _,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
if v.Name == blacklisted_test then
v:Destroy()
end
end
What you are doing wrong is checking the name of an object, a string, against a table. A string and a table are never the same, so this will always return false.
An easy fix is to check if table.find(blacklisted_test, v.Name) then.
This will go through the table, and return where it found the given item. Or if it does not exist within the table, it will return nil, which is a falsy value.
local blacklisted_test = {'test1','test2'}
for _,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
if table.find(blacklisted_test, v.Name) then
v:Destroy()
end
end
A more performant solution though, is to set all blacklisted items as the key, and true as value.
Then you can index blacklisted_test[v.Name], and if that is true, it's blacklisted.
local blacklisted_test = {test1 = true, test2 = true}
for _,v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do
if blacklisted_test[v.Name] then
v:Destroy()
end
en
2 comments
Your table seems fine here. Please post your full source code as I don't see anything wrong with the code that is posted as of right now.
oh sorry i wrote wrong.