ROBLOX | 参数1缺失或为nil?
2017-5-23 12:6:23
收藏:0
阅读:93
评论:2
我在lua方面的经验不太多,所以我来寻求帮助。我目前正在为一个叫做ROBLOX的游戏编写脚本,但我在我的脚本中遇到了一个问题,这个问题来自于这里的一个小部分
me.Chatted:connect(function(msg)
if string.sub(msg,1,5) == "!kick" then
local PLAYER = (''.. string.sub(msg,6))
KICK('game.Players.PLAYER')
end
end)
(我得到的错误是:参数1缺失或为nil)
我有点迷茫,但这是我脚本的剩余部分...
local me = game.Players.LocalPlayer
function KICK(PLAYER)
spawn(
function()
local function SKICK()
if
PLAYER.Character
and PLAYER.Character:FindFirstChild('HumanoidRootPart')
and PLAYER.Character:FindFirstChild('Torso')
then
local SP = Instance.new('SkateboardPlatform', PLAYER.Character)
SP.Position = Vector3.new(1000000, 1000000, 1000000)
SP.Transparency = 1
PLAYER.Character.HumanoidRootPart.CFrame = SP.CFrame
PLAYER.Character.Torso.Anchored = true
end
end
spawn(
function()
repeat
wait()
if PLAYER ~= nil then
SKICK()
end
until not game:GetService('Players'):FindFirstChild(PLAYER.Name)
if not game:GetService('Players'):FindFirstChild(PLAYER.Name) then
print('REMOVED ' .. PLAYER.Name)
end
end
)
end
)
end
然后这就是错误发生的地方
me.Chatted:connect(function(msg)
if string.sub(msg,1,5) == "!kick" then
local PLAYER = (''.. string.sub(msg,6))
KICK('game.Players.PLAYER')
end
end)
点赞
用户7275671
你正在传递一个字符串并尝试获取其名称,这是错误的。
你应该将 KICK('game.Players.PLAYER') 改为 KICK(game:GetService("Players")[PLAYER])。
你想将玩家对象/用户数据传递给函数,而不是字符串。
由于 "game.Players.PLAYER" 的名称是 nil,因此错误回复为 "参数缺失或为 nil"。
2018-10-30 01:02:09
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

在你的代码部分中:
local PLAYER = (''.. string.sub(msg,6)) KICK('game.Players.PLAYER')看起来你改变代码时犯了一些语法错误。应该像这样:
local PLAYER = string.sub(msg,6) KICK('game.Players.' .. PLAYER)但这也不太对。你将字符串
'game.Players.' .. PLAYER传递给函数KICK(),但是KICK()根据你对PLAYER.Character和PLAYER.Name的使用,使用它的参数PLAYER就像它是一个 Player 对象一样。你传递了一个字符串并尝试像一个 Player 对象一样使用它。修复这个问题的一个方法是将 Player 对象传递给
KICK(),而不是一个字符串。例如:local PLAYER = string.sub(msg,6) KICK(game:GetService('Players'):FindFirstChild('game.Players.' .. PLAYER))这个修订找到与用户名
'game.Players.' .. PLAYER相对应的 Player 对象,然后将 它 传递给KICK()。现在,虽然这纠正了你代码中更明显的一个问题,但似乎并不完全能够解决你提到的问题,即 "参数1丢失或空值",但是这还不确定。如果你做出这些更改,它是否可以正常工作?