【发布时间】:2021-08-23 18:54:50
【问题描述】:
我正在尝试检查玩家背包中是否有 2 瓶 Bloxy 可乐 如果有 2 个则摧毁另一个
我在脚本中尝试了这段代码,但没有成功
local tmpTable = {} -- store items names
for I,v in pairs(player.Backpack:GetChildren()) do -- loop through all items found
if tmpTable [v.Name] ~= nil then -- checks if item exists in the list
print("a duplicate has been found") -- found item e.g. a duplicate
v:Destroy() -- deletes tool
else
tmpTable [v.Name] = "BloxyCola" -- we don't need to use the value we are only using the key
print("item added to list")
end
end
【问题讨论】:
-
“没用”是什么意思?有错误吗?还是只是没有删除重复项?为什么首先有重复?您不应允许添加该项目而不是稍后将其删除。该代码的输出是什么?它打印什么?它与您的预期有何不同?
-
副本未被删除。没有打印。