Hey all, beginner scripter here. I was wanting to see if I could make a script where if the player dies, their points are removed by a factor of 10 each time they die.

Apparently the output gives out the following error:

Workspace.MyFavPart.FavPartKillScript:6: attempt to index nil with 'leaderstats'

I have tried a few possible solutions, but to no avail.

Here's the code provided below. May I ask that you please be respectful as again I'm learning and I have a beginner level of experience retaining to Roblox Lua.

local favpart = script.Parent

favpart.Touched:Connect(function(hit,plr)
	local Fire = Instance.new("Fire")
	local Char = hit.Parent 
	local playerpts = plr.leaderstats.Points
	
	
	if hit.Parent:FindFirstChild("Humanoid") then
		while wait(0.5)do
			Fire.Parent = Char.HumanoidRootPart
			wait(1)
			Char.Humanoid:TakeDamage(25)
			wait(1)
		
		end
		if Char.Humanoid.Health == 0  then
			playerpts.Value = playerpts.Value - 10
		end
	end
end)

Here's also the code for the leaderboard script if anyone needs to see.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Points = Instance.new("IntValue",leaderstats)
	Points.Name = "Points"
	Points.Value = 10
	
end)