Save your player data with ProfileService! (DataStore Module)

Hmm… I’d have to look at your code to see exactly where the problem is. I can help you with the functions related to Profile.Data or Profile.MetaData but not GlobalUpdates(I’m not there yet).

It seems this warning only happens when I’m in Studio, so it doesn’t appear in-game. I don’t think it has anything to do with my code though since it is directly copied from the Wiki. Thank you for the help anyways.

From my understanding, so long as the error is not excessive, I don’t believe it’s an issue.

This is something loleris has addressed in the Troubleshooting Section of the ProfileService GitHub page, in addition to a post from a few months ago in this topic:

1 Like

Yeah, I usually get a warning if I run studio and then stop the game 3 seconds later. Or when usually there’s a process going on which I assume the ProfileService autosaving and I cancel that by accident and it throws an error.

All in all:
1: Starting studio and immediately stopping it will cause an error.
2: Stopping studio while there’s I presume an autosave the ProfileService is doing will also throw an error.

1 Like

Is os.time() being innacurate still a problem nowadays? (Kind of wanted to know)

Don’t worry about the AssumeDeadSessionLock setting since it’s only relevant when servers actually leave dead session locks (e.g. server crash) and that won’t happen too often. We’d need a long track record os os.time() being completely accurate to rely on it more.

2 Likes

Over the past few days, joining my game that uses ProfileService has taken an extremely long time to actually load the data. I join the game, the DataManager detects that a player joined, but the problem seems to be with the ProfileService script and not the DataManager as a profile is not received from ProfileService for sometimes up to 2 minutes. This happens in new servers only when I am the first to join. The problem does not occur when testing in studio. I thought maybe something I added recently was making the game lag on startup but that doesn’t seem to be the case. All other scripts execute on time as well. Any advice or suggestions are highly appreciated! Thanks!

Showing the script could show why. I haven’t seen this. Also make sure you’re using the most recent version. If this problem is “unfixable”, you might want to use the loading method “Cancel”, and then if no profile is found, kick the player.

1 Like

Make sure to read through the troubleshooting page in official documentation. Profiles do not clean themselves after the player leaves and you must make sure all profiles are released after use.

1 Like

Thanks for your help! Turns out the problem happened because I was trying to save a Color3 to the datastore which Roblox cannot serialize. So if anyone else runs into the problem of slow profile loading times, definitely check to see if you’re saving a value that you can’t since it seems to apply not only to saving data but also loading it.

2 Likes
local saveStructure = {
	GroupReward = false,
	Currency = 0,
	NetWorth = 0,
	ObjectData = {},
}
local PlayerProfileStore = ProfileService.GetProfileStore("PlayerData7", saveStructure)

I want to add a new value in “saveStructure”, but without having to change the PlayerData7. Because if I want to add (RemovedPart = {},) and do table.insert in a divrend script it gives a error. Only if I change the key to PlayerData8 (or something els) the error removes, but then all the data of the player is gone. So how am I gonna do this?

I made a script that puts all console logs in a string, and spits it out to a Discord webhook upon server close. This is useful for people who are debugging issues with releasing profiles, and don’t have a second person to be in the server to prevent it from closing.

local Url = "WEBHOOK_URL"
local Messages = ""

game.LogService.MessageOut:Connect(function(Message, Type)
	Messages = Messages..Message.."\n"
end)

game:BindToClose(function()
	local Success, Message = pcall(function()
		local Data = {
			["username"] = "Console Monitor",
			["content"] = Messages,
		}
		Data = game.HttpService:JSONEncode(Data)
		game.HttpService:PostAsync(Url, Data)
	end)
	if Success ~= true then
		local Data = {
			["username"] = "Console Monitor",
			["content"] = Messages,
		}
		Data = game.HttpService:JSONEncode(Data)
		game.HttpService:PostAsync(Url, Data)
	end
end)

You can use reconciliation to fill any key/value pairs that the player’s profile doesn’t have from the referenced template. This is documented on the GitHub page:

Profile:Reconcile() Documentation

:Reconcile() used in an example codeblock (Also shown below)

local function PlayerAdded(player)
    local profile = GameProfileStore:LoadProfileAsync(
        "Player_" .. player.UserId,
        "ForceLoad"
    )
    if profile ~= nil then
>>>     profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
        profile:ListenToRelease(function()
            Profiles[player] = nil
            -- The profile could've been loaded on another Roblox server:
            player:Kick()
        end)
...

Might be having a severe issue with our game. It’s non-stop erroring-

It keeps going in a cycle, exhausing GetAsync requests on DataStore.

What’s the best way of just setting a players data as fresh and asking the player to contact the developer to restore data?

Seems to be that ProfileService is looping if it can’t find ActiveSession. Do I just ‘nil’ a player then?

See official documentation troubleshooting page and check your own game code data store usage from other scripts. Make sure you’re releasing profiles as unreleased profiles will keep autosaving indefinitely.

question: does profile service automatically not save in studio or do we have to code that yourself

1 Like

All listeners attached to a Profile (via :ListenToRelease(), GlobalUpdates:ListenToNewActiveUpdate(), etc.) will be garbage collected after the Profile is released and all references to it are forgotten.

This information can be found in the ProfileService troubleshooting page

1 Like

Hey @loleris , I was using your ProfileService module today when I came across an error in the ProfileService module. The error is with a function that is trying to execute in a loop many many time. This only happens when testing with more than 2 people in the server. Any idea what might be wrong?

DeepCopy functions usually error when there exists a circular reference inside the table being deep copied. In ProfileService deep copy is ran for the default data template. ProfileService also deep copies Profile.Data in mock mode.