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

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

Asked by 5 years ago

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

0
Please use a code block it is so hard to read if you just paste it as text. Enomphia 39 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

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”) Gorgon_Games 0 — 5y
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 SupremeStarfish 21 — 5y
0
I was using a different tutorial. It seems as though waitforchild creates the same error. Gorgon_Games 0 — 5y
Ad

Answer this question