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

Attempt to index nil with 'leaderstats'?

I am making a zombie shooting range game that has levels. Whenever I try to access the leaderstats level value it returns the error: Attempt to index nil with 'leaderstats'. Here is the code:

game.Workspace["Shooting range"].LevelSeven.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player:WaitForChild("leaderstats").Level.Value == 7 then
		remote3:FireClient(player)
	end
end)

If you need anything extra just let me know.

1 answer

✓ Accepted answer

Try using:

if player then
	if player:WaitForChild("leaderstats").Level.Value == 7 then
		remote3:FireClient(player)
	end
end

Checking if the player actually exists, if the GetPlayerFromCharacter function was successful

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