【问题标题】:Roblox Argument 1 Missing Or NilRoblox 参数 1 缺失或无
【发布时间】:2018-07-14 11:06:00
【问题描述】:

我正在尝试制作一个方块,当它被特定工具击中时,它会消散并给玩家一些 XP。但是,当我运行我的代码时,我收到一条错误消息“Argument 1 Missing Or Nil”。我的代码如下。

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)  

请帮忙!

【问题讨论】:

  • 它会给你一个行号吗?那里有一堆参数(括号中的东西)

标签: roblox


【解决方案1】:

我看到了 2 个问题,它们都是同一类型的问题。

问题 1

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

local player = game.Players:FindFirstChild(plr)

问题 2

第二个问题在你的赋值语句中:

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

在最后一行,您尝试设置JobXPValue,但是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

【讨论】:

    猜你喜欢
    • 2020-09-20
    • 2020-12-17
    • 2017-10-22
    • 2015-06-01
    • 2019-05-10
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    相关资源
    最近更新 更多