Conditions being met, nothing happening

I have this pickup thing I made and it inserts a item and its value into my inventory table but the problem is that Im trying to check if the player already has the item and if they dont already have it but its not printing anything

-- info[2] is the amount of the item
-- info[1] is the item name
local Inventory = _G.PlayerData[plr.UserId]["Inventory"]
	info[3]:Destroy()
	if info[2] > 3 or info[2] < 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end
	for idx,tabl in ipairs(Inventory) do
		if not Inventory[idx][1] then -- doesnt print anything
			print(info[1].." is not in "..plr.Name.."s Inventory.")
		end
	end
1 Like

Try this:

-- info[2] is the amount of the item
-- info[1] is the item name
local Inventory = _G.PlayerData[plr.UserId]["Inventory"]
	info[3]:Destroy()
	if info[2] > 3 or info[2] < 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end
	for idx, tabl in pairs(Inventory) do
		if not Inventory[idx] then -- if not Inventory[1] then(Alternative)
			print(info[1].." is not in "..plr.Name.."s Inventory.")
		end
	end

Edit: Updated.Code: @loveicicle, test me, aaaaah.

Unfortunately its still not printing out anything, any ideas whats wrong?

I’m not sure I’m aware of the whole picture, but it could be that it changes after you do the if statement. So you might have to use something like .Changed, or some sort of way to check those conditions in the if statement after if changes, not before. I’ll keep looking for anything that jumps out at me though.

Well Im not using actual objects everything is in scripts using tables

Then perhaps you’d have to use some sort of listener to fire to your script once the player gets an item. I was going to say use an infinite loop, but I’d discourage against using those, as it’s inneficient and in most cases there’s a better way to go about things.

Could you provide more info about what you’re doing? Like, when does this script activate - when something happens, or what?

this is literally the whole script

remote.OnServerEvent:Connect(function(plr,info)
	local Inventory = _G.PlayerData[plr.UserId]["Inventory"]
	info[3]:Destroy()
	if info[2] > 3 or info[2] < 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end
	local function UpdateUI()
		local InventoryUI = plr.PlayerGui:WaitForChild("Inventory")
		local Template = InventoryUI.InventoryTemplates.ImageButton:Clone()
		local InventoryFrame = InventoryUI.main.InventoryFrame
		Template.Visible = true
		Template.Parent = InventoryFrame
	end
	UpdateUI()
end)

When does the RemoteEvent fire to the server?

the itemname,iteminstance and the value

Oh sorry, I meant when, not what

Its when i pick up something

local debounce = false
uis.InputBegan:Connect(function(i,t)
	if t then return end
	if i.KeyCode == Enum.KeyCode.F and not debounce then
		debounce = true
		local function Pickup()
			for i,v in pairs(game.Workspace.Items:GetChildren()) do
				for index,tabl in pairs(ItemStorage.Items) do
					if v:IsA("Part") and v.Name == ItemStorage.Items[index][1] and (humrp.Position - v.Position).Magnitude < 5 then
						remote:FireServer(v.Name,math.random(1,3),v)
					end
				end
			end
		end
		Pickup()
		wait(.35)
		debounce = false
	end
end)

I advise adding a print statement above the condition to print the same thing (Inventory[idx][1] or simply tabl[1] as it’s the same thing) to check what the value actually is and know for certain the condition truly is met.

Yeah I tried something of that nature and its still not working or printing out anything

Try doing some debugging using print().

EDIT: Whoops, didn’t see @BanTech 's reply yet

Ive tried debugging and tried printing out Inventory[idx][1] before the if statement and it works

What did it print in this statement? false? nil?

Try printing inside of the if statement. That’ll tell you for sure if the conditions are being met.

@BanTech
@MJTFreeTime
I decided to get rid of the table and just use single arguments and when I dont insert it into the table it prints nothing at all in the console

remote.OnServerEvent:Connect(function(plr,itemname,value,iteminstance)
	local Inventory = _G.PlayerData[plr.UserId]["Inventory"]
	iteminstance:Destroy()
	if value > 3 or value < 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end
	for idx,tbl in ipairs(Inventory) do
		print(Inventory[idx][1])
	end
	local function UpdateUI()
		local InventoryUI = plr.PlayerGui:WaitForChild("Inventory")
		local Template = InventoryUI.InventoryTemplates.ImageButton:Clone()
		local InventoryFrame = InventoryUI.main.InventoryFrame
		Template.Visible = true
		Template.Parent = InventoryFrame
	end
	UpdateUI()
end)

What I pass onto the server

There’s one problem that could happen. You’re passing “math.random(1,3)”, which I believe picks 1 or 3, and any number in between. Then in your script you say:

if value > 3 or value < 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end

You’ll probably want to make it this:

if value >= 3 or value <= 1 then
		plr:Kick("Imagine trying to change an item's val . . . ")
	end

EDIT: The thing is, it could land on 1 or 3. Then, the way you have it now, it wouldn’t meet the conditions, as you’re only checking between 1 and 3.

It’s probably not the main problem, but something on the side to check.

changing it wouldnt really help… im checking to see if the number that the server receives is between 1 and 3, not any lower than 1 and not any higher than 3 if I tried your method if the player got 3 it would kick them and if they got 1 it would kick them