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

Attempt to index local 'Player' (a nil value) how to fix?

Asked by
R18PMC 0
5 years ago
Edited 5 years ago

I have been scripting on Roblox for about a year now but I have never had to use these kind of values and commands so I am still a newbie. I have looked at other peoples questions on this same error and also have watched videos on it but it hasn't helped me a single bit. I have tried everything I could think of but I just need help. I am trying to make a tree that gives you wood when you cut it down. Here's the script...

local z = script.Parent
local x = z.Log
local y = z.Leaves
local hits = 0
local maxhits = 8

x.Touched:connect(function(hit)
    if hit.Name == "PlainAxe" then
    hits = hits + 1

    if hits >= maxhits then

        hits = 0

        -- This is what I need Help With...
        local char = hit.Parent:FindFirstChild("Humanoid")
        local player = game.Players:GetPlayerFromCharacter(char)
        player.Stats.Wood.Value = player.Stats.Wood.Value + 10

        -- The rest of this works just fine when I remove the segment above.
        script.Parent.Leaves.Position = Vector3.new(-444.95, -34.9, -282.2)
        script.Parent.Log.Position = Vector3.new(-444.9, -24.25, -282.55)

        wait(10)

        script.Parent.Leaves.Position = Vector3.new(-444.95, 22.9, -282.2)
        script.Parent.Log.Position = Vector3.new(-444.9, 9.75, -282.55)

        print("Complete")

        end
    end
end)
0
were getting somewhere! I changed it up a bit and now i just need to make it wait untill the "wood" value has loaded R18PMC 0 — 5y
0
You don't pass the humanoid through `GetPlayerFromCharacter` you pass reference to the model of the attempted character. EpicMetatableMoment 1444 — 5y

1 answer

Log in to vote
0
Answered by
royee354 129
5 years ago
Edited 5 years ago

Your problem is that the char variable is a humanoid also it seems like you forgot a "="

2
Should have been a comment User#24403 69 — 5y
0
I fixed the "=" thing but its giving me the same error, if its not supposed to be "Humanoid" then what else could it possibly be? R18PMC 0 — 5y
0
hit.Parent which is the character royee354 129 — 5y
Ad

Answer this question