Help with Setting Boolean to False After Player Dies

game.Players.PlayerAdded:Connect(function(plr)

	local P = Instance.new("BoolValue", plr) or 0
	P.Name = "isShiftlock"


end)

This is a script in Serverscriptservice, that creates a BoolValue when a player joins. I want it so that everytime a player dies, the boolvalue is set to false.

game.Players.PlayerAdded:Connect(function(plr)
    local P = Instance.new("BoolValue", plr)
    P.Name = "isShiftlock"

    local function onPlayerDied()
        P.Value = false
    end

    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
        humanoid.Died:Connect(onPlayerDied)
    end)
end)

I have tried that but it does not work.

Try this instead:

game.Players.PlayerAdded:Connect(function(plr)
    local BoolValue = Instance.new("BoolValue", plr)
    BoolValue.Name = "BoolValue"
    BoolValue.Value = true

    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")

        humanoid.Died:Connect(function()
            BoolValue.Value = false
        end)
    end)
end)

This script creates a bool value that is set to true by default but once the player dies, it is set to false.