首页 文章

Roblox Argument 1 Missing Or Nil

提问于
浏览
1

我试图制作一个块,当它被特定工具击中时,它会消失并给玩家一些XP . 但是,当我运行我的代码时,我得到一个错误,说“参数1缺失或无” . 我的代码如下 .

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == 'Vacuum' then
        local plr = hit.Parent.Parent.Name
        script.Parent.CanCollide = false
        script.Parent.Transparency = 1
        local exp = 2
        local player = game.Players:FindFirstChild(plr.Name)
        local plrcurrentexp = player.leaderstats.JobXP.Value
            plrcurrentexp.Value = plrcurrentexp + exp
        wait(120)
        script.Parent.CanCollide = true
        script.Parent.Transparency = 0  
    end
end)

请帮忙!

1 回答

  • 1

    我看到两个问题,其中两个都是同一类型的问题 .

    Problem 1

    第一个问题是找到玩家 . 你设置 plr = hit.parent.Parent.name ,但然后运行 FindFirstChild(plr.Name) ,但这不起作用,因为 plr 已经是玩家的 Name . 相反,你应该这样做:

    local player = game.Players:FindFirstChild(plr)
    

    Problem 2

    第二个问题出在你的任务说明中:

    local exp = 2
    local player = game.Players:FindFirstChild(plr.Name)
    local plrcurrentexp = player.leaderstats.JobXP.Value
    plrcurrentexp.Value = plrcurrentexp + exp
    

    在最后一行你试图设置 ValueValue ,但 plrcurrentexp 不是 JobXP ,它是 Value .

    所以你现在正在做的是 player.leaderstats.JobXP.Value.Value = plrcurrentexp + exp ,这是错误的 .

    而是这样做:

    local exp = 2
    local player = game.Players:FindFirstChild(plr.Name)
    local plrcurrentexp = player.leaderstats.JobXP
    plrcurrentexp.Value = plrcurrentexp.Value + exp
    

相关问题