Unable to save Dictionary with UserData

I’m scripting a datastore system for my game, but when I tried to save this dictionary:

local DataTemplate = {
	LastTimeSaved = DateTime.now(),
	Cash = 0
}

An error, with error code 103 was thrown.

I looked online for a solution, and found

game.HttpsService:JSONEncode() 
game.HttpsService:JSONDecode() 

However, when I utilized them, it would print:

{"LastTimeSaved":null,"Cash":0} --Prior to JSONDecode
 {  ["Cash"] = 0 }  --After JSONDecode

Does anybody know a workaround (with or without JSONDecode/Encode) or anything of the sort?

Wasn’t aware of DateTime in my last post, figured it was your own system you made. After searching up, DateTime.now() seems to return an object which can’t be saved or JSONEncoded. After looking into it, what you’re doing seems to essentially serve same purpose as using os.time(), so why not use that instead? It returns a number which can be saved rather than userdata which can’t.

image

2 Likes

Just save the DateTime.now().UnixTimestampMillis instead and recreate the datetime datatype by using DateTime.fromUnixTimestampMillis() function when decoding.