PDF of $|X-Y|$ when X and Y are independent uniform on $\left[0,l\right]$ pretty much trying to solve the question in the title, what I tried is:

*

*consider $Z=\left|Y-X\right|$, and try to compute $F_{Z}\left(t\right)=1-P\left(Z>t\right)=1-\left(P\left(X-Y>t\right)+P\left(Y-X\geq t\right)\right)$

*So I propused a random variable $Z_{1}=Y-X$, and got $$f_{Z_{1}}\left(x\right)=\intop_{-\infty}^{\infty}f_{Y}\left(y\right)f_{-X}\left(x-y\right)dy=\intop_{x}^{l}f_{Y}\left(y\right)f_{-X}\left(x-y\right)dy$$ which came out as $\frac{l-x}{l^{2}}$

*I then compute $P\left(X-Y>t\right)=\intop_{t}^{\infty}f_{Z}\left(x\right)dx=\intop_{t}^{l}f_{Z}\left(x\right)dx=\frac{\left(l-x\right)^{2}}{l^{2}}$ and deduced $f_{Z_{1}}\left(t\right)=1-\frac{2\left(l-x\right)^{2}}{l^{2}}$ so it came out that $f_{Z}\left(t\right)=\frac{4(l-x)}{l^{2}}$, but checking on other theards it seems that the right answer is $\frac{2(l-x)}{l^{2}}$. when $x\in\left[0,l\right]$ of course

I am trying to understand what went wrong, maybe  i got $f_{Z_{1}}\left(x\right)$ wrong? at the other theards they used some methods I don't know yet, so I will appreciate if you can help me solve it this way, thank you!
 A: 
There are some calculations you make that I can't follow, but the idea makes sense to me. Maybe you should check the limits of integration, supports, etc. I will write a version of the solution as I commented previously with an idea that I once learned from a friend. The idea is basic: work on $[0,1]$ taking advantage of uniformity and use definitions moving to $[0,L]$.

Suppose $X,Y\sim U[0,L]$ for $L>0$. Then notice that transformation $$(Z_1,Z_2)\to\left(\frac{1}{L}X,\frac{1}{L}Y\right) \implies Z_1,Z_2\sim U(0,1).$$
Thus for $t\in [0,L]$, we have
$$P(|X-Y|\leqslant t)=P(|LZ_1 -LZ_2 |\leqslant t)=P(|Z_1-Z_2)|\leqslant t/L),\quad (*)$$
Thus, it is sufficient to work with $X, Y\sim U[0,1]$ and then use $(*)$ to conclude with the result. Indeed, suppose that $X,Y\sim U(0,1)$ and by independence the joint density is given by
$$f(x,y)=\begin{cases}1,\quad 0\leqslant x,y\leqslant 1,\\0\quad \text{otherwise}\end{cases}$$
We want $P(|X-Y|\leqslant t)$ for $t\in [0,1]$. But, by complement we have $$P(|X-Y|\leqslant t)=1-P(|X-Y|\geqslant t)$$
Thus, it is sufficient to find  $\boxed{P(|X-Y|\geqslant t)}$.
Since we want to find $P(|X-Y|\geqslant t)$ for $t\in [0,1]$ so we need to know the points $(x,y)$ so that $|x-y|\geqslant t$. The easy way is to locate the points that divide the regions $x-y\geqslant t$ or $x-y\leqslant -t$. These points are on the straight lines $|x-y|=t$ that is $x-y=t$ or $-(x-y)=t$, a first plot it useful.

It is easier to use geometry here, but we can continue using of the definition, so we need to use doubles integrals.
$$P(Y-X\geqslant t)=\int_{t}^{1}\int_{0}^{y-t}1\, dxdy=\frac{(t-1)^{2}}{2}$$
$$P(X-Y\geqslant t)=\int_{t}^{1}\int_{0}^{x-t}1\, dydx=\frac{(t-1)^{2}}{2}$$
Thus, $$P(|X-Y|\leqslant t)=1-P(|X-Y|\geqslant t)=\boxed{1-P(Y-X\geqslant t)-P(X-Y\geqslant t)}$$
give $$\boxed{P(|X-Y\leqslant t)=1-(t-1)^{2}}$$
The probability density function is given so $$\boxed{f(t)=\begin{cases}2-2t, 0\leqslant t\leqslant 1,\\0,\quad \text{otherwise}\end{cases}}$$
Using $(*)$, then we have $P(|X-Y|\leqslant t/L)=1-(t/L-1)^{2}$ and taking the derivative we find the probability density function $$\boxed{f(t)=\begin{cases} 2(L-t)/L^{2}\quad 0\leqslant t\leqslant L,\\0,\quad \text{otherwise}\end{cases}}$$
