arrays - 有没有办法检查一个数组的任何内容是否在 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)
我就可以测试脚本而不会太早执行,并且使用我的用户名是为了测试。此外,当我对其进行测试时,它什么也不做。
解决方案
您可以使用该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
推荐阅读
- python - 有没有办法将现有标签传递给另一个类以使其闪烁
- javascript - 如何通过鼠标拖动来滚动 div?反应钩子
- excel - VBA:如果数组中的值为负数或空值,如何添加错误?
- hdfs - 从 Ambari 控制台向正在运行的集群添加新的 DataNode
- java - 如何使用 GSON 将 JSON 反序列化为 ByteBuffer?
- bluetooth - 配对时如何使硬件设备显示为音频设备?
- react-native - SafeAreaView 放在背景上后不占用整个屏幕
- javascript - 关闭asp.net核心中的模态表单后如何刷新父页面
- simulation - 在anylogic中如何确定排队问题中服务时间和空闲时间的成本?
- javascript - 在javascript中用零完成数组中的缺失序列