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

Why wont my script match a players item to a list of items?

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)

1 answer

if v.Name == g.Name then

they arent the exact same object, they are clones if anything so match their names instead

2 comments

0

That would make sense, but now the script always runs, "IllegalItemFound" even if there are no items in the players inventory.

0

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

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