1
votes

I am trying to make a block that when it is hit by a specific tool, it dissapers and gives the player some XP. However, when I run my code I get an error saying "Argument 1 Missing Or Nil". My code is below.

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)  

Please Help!

1
Does it give you a line number. There are a bunch of arguments (things in brackets) there - Nick.McDermaid

1 Answers

1
votes

I see 2 problems, of which both are the same type of problem.

Problem 1

The first problem is finding the player. You set plr = hit.parent.Parent.name, but then run FindFirstChild(plr.Name), but that doesn't work since plr is already the player's Name. Instead you should do:

local player = game.Players:FindFirstChild(plr)

Problem 2

The second problem is in your assignment statement:

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

On that last line you're trying to set the Value of JobXP, however plrcurrentexp isn't JobXP, it's the Value.

So what you're doing right now is player.leaderstats.JobXP.Value.Value = plrcurrentexp + exp, which is wrong.

Instead do this:

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