Ive asked this question twice already on this site and im starting to get desperate, ive been stuck on this for weeks, and no matter what I do the code will not work. Im trying to scan a player's inventory and check to see if any of their items match a master list of prohibited items, and to my eyes, the script should work, but I must be doing something wrong.
local IllegalItemFound
script.Parent.Touched:Connect(function(hit)
local players = game:GetService("Players")
local Player = players:GetPlayerFromCharacter(hit.Parent)
local Inventory = Player.Backpack
local ItemsInInventory = Inventory:GetChildren()
local prohibitedItems = {game.ServerStorage.ProhibitedItems["SR-60 Default"], game.ServerStorage.ProhibitedItems.CombatKnife}
for i, v in pairs(ItemsInInventory)do
for a,g in pairs(prohibitedItems) do
if v == g then
print("IllegalItemFound")
print(Inventory[v.Name])
IllegalItemFound = true
end
end
end
if IllegalItemFound then
print("IllegalItemFound")
else
print("PlayerCleared")
end
end)

2 comments
That would make sense, but now the script always runs, "IllegalItemFound" even if there are no items in the players inventory.
set illegalItemfound back to false after doing the checks, someone might already have made it to true making it print that it found an illegal item