首页 > 解决方案 > 有没有办法检查一个数组的任何内容是否在 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)我就可以测试脚本而不会太早执行,并且使用我的用户名是为了测试。此外,当我对其进行测试时,它什么也不做。

标签: arraysluaroblox

解决方案


您可以使用该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

推荐阅读