Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why I have this: "attempt to index local 'player' (a nil value)" ?

Asked by 4 years ago

Hello ! I made this script but it doesn't work, I have this error which appears but why? My error: attempt to index local 'player' (a nil value) at the line 3 and 15

script.Parent.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    player.Price.Value = 20
    print(hit.Parent)
    if hit.Parent.Name == "Pickaxe" then
        script.Parent.BrickColor = BrickColor.new("Really blue")
        local pickaxe = hit.Parent.Parent:WaitForChild("Pickaxe")
        pickaxe:WaitForChild("LocalScript").Disabled = false
    end

end)
script.Parent.TouchEnded:Connect(function(hit)
    print(hit.Parent)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    player.Price.Value = 10
    script.Parent.BrickColor = BrickColor.new("Really red")
    player.Price.Value = 10
    local pickaxe = hit.Parent.Parent:WaitForChild("Pickaxe")
    pickaxe:WaitForChild("LocalScript").Disabled = true     
end)
0
put print(player) tell me what would come up AntoninFearless 622 — 4y
0
AntoninFearless Sometimes I have nil (when I get in and out) and sometimes my player name Altair77100 6 — 4y
0
You have to run an if conditional statement to check to see if a player touched the part. It is likely detecting the part underneath it. DeceptiveCaster 3761 — 4y

Answer this question