MadStudioRoblox / ProfileService

Universal session-locked savable table API

Home Page:https://madstudioroblox.github.io/ProfileService/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`BindToSave` function for profiles

angrybino opened this issue · comments

commented

Currently, there is no way to control how profiles are saved. A BindToSave function for profiles would be really useful as it would allow users to control how they want to save the profile. This also gives the user more flexibility on creating custom data interfaces.

  • Return Save to save the profile
  • Return Cancel to cancel the save for the profile

Use cases:

  • Checking if a profile was updated, if not, return Cancel to cancel the save (prevent unnecessary requests).

Example code:

profile:BindToSave(function()
       if (profile:GetMetaTags("IsUpdated") == true) then 
              return "Save"
       end
       return "Cancel"
end) 

This would also prevent additional throttling.

Controlling how ProfileService saves data or attaching listeners to when (before or after) ProfileService does the saves is firstly redundant, because the built-in auto save cycle and release saving are already going to ensure properly saved data well beyond a necessary threshold. It's also worth mentioning that manual saving via Profile:Save() is not (entirely) the right tool to ensure proper developer product saving - Roblox API provides unique PurchaseId purchase identifiers via the MarketplaceService.ProcessReceipt callback where said identifiers can be used to check whether the profile has properly saved the identifier via Profile.MetaData.MetaTagsLatest.

ProfileService has a system that may steal your active profiles at any time from an external server. This means that in this case profile management code would only receive an event that the profile is stolen without any chance to make a final save and the only thing that's going to be saved is the last state Profile.Data was in. That's why you're supposed to always have Profile.Data in the most recent savable state at all times - any changes to player data have to be instantly reflected inside Profile.Data instead of waiting for the next save cycle. All of that is part of how ProfileService ensures data safety.