I'm having data loss

Data loss is not too common, however not impossible.
I would recommend using ProfileService as it has excellent features, including session-locking (useful if you have a trading system as it prevents duplication and so on).

ProfileService
ProfileService — API

Regardless, I do suggest that you add a game:BindToClose() and save on an interval, ex. every 2-3 minutes.
You should also wrap your calls in a pcall (protected call) and handle errors when they occur.

The last thing I suggest is having everything inside a table, like this:

local SaveTable = {
	GEMS		= 0,
	COINS 		= 0,
	REBIRTHS	= 0,
	PLANET		= 'DEFAULT VALUE',
}

That way, you only need to write to the datastore once, and don’t risk some of the calls failing.
Usage: DataStoreKey:SetAsync(Key, SaveTable)

2 Likes