Script Breaking when player dies

So i encountered a bug in a project i was working on where you get one point when you step on a block but when i die the script breaks and i dont get points for stepping on the blocks anymore

local platform = script.Parent

local isTouched = false

local function fade()
	if isTouched == false then
		isTouched = true
		for count = 1, 10 do
			platform.Transparency = count / 10
			wait(0.1)
		end
		platform.CanCollide = false
		wait(3)
		platform.CanCollide = true
		platform.Transparency = 0
		isTouched = false
	end
end

platform.Touched:Connect(fade)

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
end

Players.PlayerAdded:Connect(onPlayerAdded)

local wasTouched = false

local function pointsAdded ()
	if wasTouched == false then
		wasTouched = true
	
	local playerList = Players:GetPlayers()
	for currentPlayer = 1, #playerList  do
		local player = playerList[currentPlayer]
		local points = player.leaderstats.Points
		points.Value = points.Value + 1
	wait(5)
	wasTouched = false
		end
	end
end

platform.Touched:Connect(pointsAdded)

Where did you put the script?
Putting a script inside of a player’s backpack would mean that it reruns every time they respawn.

Putting your script in ServerScriptService might resolve this issue.

i put that script in the brick itself , i dont have any scripts in a players backpack

Okay so, make a Script inside of ServerScriptService containing the following:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	points.Parent = leaderstats
end)

And put the following in a LocalScript inside of the brick:

local players = game:GetService("Players")

local touchPart = script.Parent

touchPart.Touched:Connect(function(part)
	local player = players:GetPlayerFromCharacter(part.Parent)
	if not player then return end
	player.leaderstats.points.Value += 1
end)