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

I keep getting "attempt to index local 'player' (a nil value) Can anyone assist?

This is the script where it is happening.

--Variables

local log = script.Parent

local logGuard = false

local function onTouch(partTouched)

local character = partTouched.Parent

local humanoid = character:FindFirstChildWhichIsA("Humanoid")

local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)

local playerStats = player:FindFirstChild("leaderstats")

local playerLogCount = playerStats:FindFirstChild("Has Log")

if humanoid and logGuard == false then

log.Transparency = 1

log.CanCollide = false

logGuard = true

playerLogCount.Value = 1

print ("You have collected a log!")

wait (5)

log.Transparency = 0

log.CanCollide = true

logGuard = false

print ("You can pick up another log")

end --End if Humanoid statement

end --End onTouch function

1 comment

0

Please use a code block it is so hard to read if you just paste it as text.

1 answer

Hahaha funny, i had this exact problem like 2 months ago anyways, i might be able to help. If you are using a serverside script this won't work you gotta use a local script.

3 comments

0

The odd thing is that when I test it...sometimes it works, sometimes it doesn't. This was the line it indicated was the problem: local playerStats = player:FindFirstChild(“leaderstats”)

0

Yeah are you using AlvinBlox's script tutorial? Im not sure, but i had that very similar problem a while, but that is strange about how it sometimes works and sometimes doesn't i suggest instead of findfirstchild try waitforchild

0

I was using a different tutorial. It seems as though waitforchild creates the same error.

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