So I am scripting right now and trying to understand how does this work:
weld.C0 = part1.CFrame:inverse() * part2.CFrame
Please explain it to me.
You could say inverse negates the matrix, so when you multiply it with regular matrix, they would sort of 'subtract'. If you are really interested how exactly that works, you can just search matrix inversion.
What happens in this situation, you find out the object space coordinates of part2. This means that you know the part2's offset from part1. If you understand vectors, it would be similar logic to:
part2.Position - part1.Position
I hope it is bit more clear, although this is bit complicated subject.