【问题标题】:Is there a way to check if any content of a array is in another array in Roblox有没有办法检查一个数组的任何内容是否在 Roblox 的另一个数组中
【发布时间】:2021-04-03 17:13:00
【问题描述】:

所以我正在尝试制作一个允许我禁止人的脚本,但主要脚本检查玩家是否在游戏中在被禁止的用户列表中被杀死或踢。这是我的代码:

local BannedUsers = {"littleBitsman"}
local Players = game.Players:GetChildren()
wait(10)
for index1,value1 in ipairs(Players) do
    for index2,value2 in ipairs(BannedUsers) do
        if Players[index1] == BannedUsers[tonumber(index2)] then
            local HumanoidToKill = workspace[value1].Character:FindFirstChildWhichIsA("Humanoid")
            if HumanoidToKill.Health >= 0 then
                HumanoidToKill.Health = 0
                print("killed " .. tostring(value1))
            end
        end
    end
end

wait(10) 是为了让我可以测试脚本而不会太早执行,并且我的用户名用于测试。 此外,当我对其进行测试时,它什么也不做。

【问题讨论】:

    标签: arrays lua roblox


    【解决方案1】:

    您可以使用table.find 函数。

    local BannedUsers = {"littleBitsman"}
    
    for _, player in ipairs(game.Players:GetChildren()) do
         if table.find(BannedUsers, player.Name) then
              player:Kick("You are banned!")
         end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-07
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      相关资源
      最近更新 更多