Hello, I have this issue where i get an error saying attempt to compare string < boolean.
code:
for counter = 1,20 do
local slot = UI:WaitForChild("Slot"..counter)
if not playerInventory[itemType]["Slot"..counter] then continue end
if not GetItemAmt(playerInventory[itemType], slot) > ItemModule[item.Name]["StackSize"] then continue end
print(counter)
end
When i do print(typeof(ItemModule[item.Name]["StackSize"])) it prints out string and when i do print(typeof(GetItemAmt(playerInventory[itemType], slot))) It also prints out string. When i print the values I get the correct values.
You are trying to compare a boolean, true/false with a string "", instead both values should be numbers.
Addition to this, you could change the follow from not number > number → number <= number
What you could do is use tonumber() on either if it returns a string with numbers in it e.g. "12345"
The issue at hand is the not instead I suggest using more brackets for and, or, not
Like shown:
not (GetItemAmt(playerInventory[itemType], slot) > ItemModule[item.Name]["StackSize"])
Last part is that you used 2 if statements instead you could use only 1:
if not playerInventory[itemType]["Slot"..counter] or not GetItemAmt(playerInventory[itemType], slot) > ItemModule[item.Name]["StackSize"] then continue end
Then you should check if the value returns a number and not nil while you use tonumber()
if tonumber(playerInventory[itemType]["Slot"..counter]) then continue end
Using everything together, the if statement would look like this:
if not playerInventory[itemType]["Slot"..counter] or tonumber(playerInventory[itemType]["Slot"..counter]) or tonumber(GetItemAmt(playerInventory[itemType], slot)) <= tonumber(ItemModule[item.Name]["StackSize"]) then continue end
add brackets because as it is a string, i believe not "string" = false
it will process the not “string” first and it returns false, which cannot be compared with a string so u can edit it to be if not (GetItemAmt(playerInventory[itemType], slot) > ItemModule[item.Name]["StackSize"]) then continue end the brackets prioritizes the comparison
Edit:
edited script here
for counter = 1,20 do
local slot = UI:WaitForChild("Slot"..counter)
if not playerInventory[itemType]["Slot"..counter] then continue end
if not (GetItemAmt(playerInventory[itemType], slot) > ItemModule[item.Name]["StackSize"]) then continue end
print(counter)
end