Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

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

0

You don't pass the humanoid through GetPlayerFromCharacter you pass reference to the model of the attempted character.

1 answer

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

3 comments

2

Should have been a comment

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?

0

hit.Parent which is the character

This discussion is preserved as it was. New answers, comments, and votes are closed.