Save your player data with ProfileService! (DataStore Module)

Thank you! However, I have one more question. Can we work with dictionaries in datastores? I put one to keep track of the skins owned by the player but I get a warning "[ProfileService]: DataStore API error [Store:“PlayerData”;Key:“Player_2400337484”] - “104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.”

It can store dictionaries, just not the dictionary you provided - see the troubleshooting page in the official documentation and you’ll sort this out.

2 Likes

DataStores save data with JSON.

This is usually just you not serializing something, Lua tables can sometimes not transform into JSON for some reasons.

JSON only supports dictionaries which only have string as the key, so no other types of keys, it also supports arrays, and the definition of array here is any table that only has indexes from 1-n, no gaps, and no other string keys inside that same array.

JSON also only supports as values: booleans, numbers, strings, and other tables which follow the same rules.
So, things like Color3s, Vector3s, CFrames, and many others need to handled manually by you.

JSON also doesn’t support cyclic-references.

2 Likes

Im only editing the inside of profile.Data but does it still apply? I also don’t connect :Release() to :BindToClose, only to .PlayerRemoving but maybe it also applies.

I fixed it, this is actually what happened: so for profile.Data, I add a DataChanged signal and a _state table that stores the original table. And then, for every table inside profile.Data, I add a KeyChanged signal which caused _state to have a KeyChanged signal when it’s not supposed to, and there is a table inside _state which keeps on repeating that which probably causes the error.

I encountered two errors whilst using your ProfileService for more information see the topic here: [ERROR] ProfileService. Please let me know if there’s a solution. Thank you!

Is it possible to get the user’s data with just the userId? Even if they are not online?

ProfileService:ViewProfileAsync(dataStoreProfileKey)
1 Like

efficient, thanks for the effort. keep up the good job

How many things can I have in a profile? C:

I’m kind of new to ProfileService, but how do you remove or add items to a table using ProfileService?

Profiles have a Data property which is a table that contains all your values. Just edit that table and you’re done.

1 Like

I do know that, but I’m just confused on where you reference it like. Do you do Profile.Data.Tables or something thats what I’m confused on.

local serProfiles = require(module)
local storeTest = serProfiles.GetProfileStore(strName, tabTemplate)
local profileTest = storeTest:LoadProfileAsync(strKey, function() return "ForceLoad" end)

profileTest.Data.Stuff1 = 1
profileTest.Data.Stuff2 = 2
profileTest.Data.Stuff3 = 3
1 Like

But can I edit it too even without them online?

I still got a bit confused, but I kind of figured it out on my own. Anyways thanks for helping.

ProfileService:OverwriteAsync(profileKey)

I tried that, but it didn’t seem to work…

My game uses a bit of an odd shutdown system- on BindToClose, players are teleported to a “holdover” server before being teleported back to the main game. This lets us do fairly seamless updates for our players.

How will this interfere with ProfileService’s attempts to save player data on BindToClose? What would be the proper way to handle something like this? Perhaps a grace period of ~20 seconds before teleporting the players to the holdover server?

What you should do teleport on them on the player’s profile’s :ListenToServerHop, and while not everyone has been teleported, yield your :BindToClose call.