怎样检查一个数组中的任何内容是否在另一个数组中的Roblox中

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

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)是为了我可以在不太早的时候测试脚本,而使用我的用户名是为了测试。 当我测试它时,它根本不起作用。

点赞
用户11886689
用户11886689

你可以使用 table.find 函数。

local BannedUsers = {"littleBitsman"}

for _, player in ipairs(game.Players:GetChildren()) do
     if table.find(BannedUsers, player.Name) then
          player:Kick("你被禁止了!")
     end
end
2020-12-26 03:18:36