I can't seem to get my head around an algorithm, I just want to know if it is possible and how it is changed even when the player who sold something is offline
Here is an article on DataStores:
http://robloxdev.com/articles/Data-store
DataStores can be used to transport data to places in a game Universe. It has to be all connected to each other, or the data cannot be transferred. It can be saved at any time and be accessed from any place within the universe. It can also be used to stop exploiters from hacking data.
It's useful, and I use it in my games that I am developing.