微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

检查玩家在 roblox 中是否有重复的工具

如何解决检查玩家在 roblox 中是否有重复的工具

我正在尝试检查玩家的背包中是否有 2 个 Bloxy Colas 如果有 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

解决方法

未删除重复项。没有打印

您在条件语句的两个分支中都打印了一些内容。如果没有打印任何内容,则意味着循环不会运行一次。这意味着 player.Backpack:GetChildren() 返回一个空表。

由于 Instance:GetChildren() 将始终返回一个表,看到一个空表意味着 Backpack 没有任何孩子。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。