Hi,
I have a tools in players backpack and every tool have inside it numbervalue. I want to check if ALL items that players have that value 0 and if all have 0 then i do something. I thought use for in pairs statement, but i can’t imagine how to make make it check if all tools have value 0. i can only check if 1 tool have its value 0 but not all. Anyone know how i can check it?
You can use ‘#’ to get the length of a list.
local numTools = #Player.Backpack:GetChildren()
if numTools == 0 then
print("Player has no tools!")
end
sorry i made a bad title. tools didnt dissapear in players inventory. all tools have a value inside it how that says how much left and if all tools have its value 0 i want to do something. but i don’t know how to check it
If you want do something when all tools are at 0, then just check to see if at least 1 tool is greater than 0.
local allToolsAtZero = true
for _, tool in pairs(Player.Backpack:GetChildren()) do
if tool.NumberValue.Value > 0 then
allToolsAtZero = false -- if one tool is greater than 0, not all tools are at 0
end
end
if allToolsAtZero then
-- do something
end
1 Like