首页 文章

ROBLOX |参数1缺失或为零?

提问于
浏览
2

我没有太多的经验,所以我来这里寻求帮助 . 我目前正在制作一个名为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)

(我得到的错误是: Argument 1 missing or 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)

2 回答

  • 0

    在这部分代码中:

    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 ,就好像它是一个Player对象,如使用 PLAYER.CharacterPLAYER.Name 所示 . 传入一个字符串并尝试像Player对象一样使用它 .

    解决此问题的一种方法是将实际的Player对象传递给 KICK() 而不是String . 例如:

    local PLAYER = string.sub(msg,6)
    KICK(game:GetService('Players'):FindFirstChild('game.Players.' .. PLAYER))
    

    此修订版找到与用户名 'game.Players.' .. PLAYER 对应的Player对象,然后将其传递给 KICK() . 现在,虽然这在您的代码中修复了一个更明显的问题,但它似乎并不能解决您引用的问题“ Argument 1 missing or nil ”,但您永远不会知道 . 如果进行这些更改,它是否正常工作?

  • 1

    你正在传递一个字符串并试图获得一个名字,这是不好的 .

    您应该将 KICK('game.Players.PLAYER') 更改为 KICK(game:GetService("Players")[PLAYER])

    您希望将播放器对象/ userdata传递给函数而不是字符串 .

    由于“game.Players.PLAYER”.Name为nil,错误回复“参数缺失或为零”

相关问题