Save your player data with ProfileService! (DataStore Module)

Damn, I was just frustrated, but I still dont like how its more complicated and there is no explanation.
What does profiles even mean?
What does GetProfileStore() do?
Why do I need to give cash?
Why does it give me an error even if i just copy and pasted
Do I have to create a leaderstat?
Why would this code even work?
What does Reconcile() do
what does :AddUserId() do?
What does profile:Release() do?
Will this actually save my data for leaderstats? and if not, why is it so misleading?

I really cannot tell at this point if this a pure joke or not…

1 Like

no, like seriously I read it again and most of my questions are answered but because I hardly know the idea of datastores and why they suck.
What is session locking?
and why do I get an error “attempted to add with a nil value.” Even in a blank game I still get that error
edit: answered this one ^
Do I need to create leaderstats??? edit: answered this one

Learn basic scripting first before attempting to work with this kind of stuff.

1 Like

well clearly I failed at the “datastore” part 15 (16 by now) times. And im still failing to make this work with leaderstats

Dude, you can watch YouTube tutorials.

This guy explains it really well.

thank you so much
i will get started immediately

1 Like

Hello, I’ve (finally) setup everything and now I’m quite unsure how to apply leaderstats. Ive heard using the .Changed method is bad? So how else would I always set it to save with the correct value?

Look further into the video I sent you. He makes an update function inside the PlayerDataHandler module and you can use that function for updating your data. To make it update the leaderstats, below where you call the update function, just reference the player’s leaderstats and the value you want to change inside it and then get the player’s profile and change the value of the leaderstat you want to change to the profile’s data.

I know this sounds really confusing but once again, watch the video until the end to understand more.

I did it a bit differently. After the player joins the IntValue.Value = profile.Data.Coins
because when the profile is released profile.Data.Coins = IntValue.Value
Edit: Do I need to edit :Set and :Update methods too?

It isn’t. You should use .Changed on stuff like values. It shouldn’t be used however to get a single property of an instance. If you’re changing the name too, use

:GetPropertyChangedSignal("Property name here"):Connect(function()

I’ve ran into an issue and I’m not sure how I should be handling this.
My ban system does a ViewProfileAsync before doing LoadProfileAsync just to not unnecessarily load a profile if they’re in another game, but when I do something like this:

local offline_data = ProfileStore:ViewProfileAsync(("Player%s"):format(userId))
-- Check if they're banned, if not then open up their data to change that:
local profile = ProfileStore:LoadProfileAsync(("Player%s"):format(userId))

It takes a really long time, as if ViewProfileAsync opened up a profile and LoadProfileAsync is trying to close it. Any ideas?

2 Likes

https://madstudioroblox.github.io/ProfileService/api/#profilestoremock

ProfileStore.Mock is a reflection of methods available in the ProfileStore object with the exception of profile operations being performed on profiles stored on a separate, detached “fake” DataStore that will be forgotten when the game session ends. You may load profiles of the same key from ProfileStore and ProfileStore.Mock in parallel - these will be two different profiles because the regular and mock versions of the same ProfileStore are completely isolated from each other.

1 Like

I have a private server system in my game that uses TeleportService to teleport players to various servers inside my experience. When a player teleports to these servers, their data sometimes loads, but most of the time doesn’t load. I would assume that the Profile:ListenToHopReady() would help solve this problem, however after reading the API, I am still confused as to where I will put that function and when to call it properly.

Can anyone help me out here? Appreciate it.

Anywhere honestly, the function you pass through ListenToHopReady will run after the profile gets released. That method just makes sure to release the profile before running the function.

So you only need a way to get the profile from the script you’re planning to teleport the player

2 Likes

I am getting a ProfileService API saving error.

Not sure what is causing it, but figured I would ask if the data template is the problem. Below is my data template and I have scripts that change the values for each player’s profile.

I read through the API documentation and it did not say this is problematic which is why I am confused.

CIV = {
		["Boulder Charger SRT"] = {
			Owned = false,
			Color = "Institutional white",
			Gas = 100,
			PlateText = "XXX-000",
			PlateTexture = "Purple",
			Insurance = true,
			Registration = true,
			Stolen = false,
		},
}

I do not see any issues with your template. Are you sure you are setting a Color3 or anything later on? What is the error specifically

Hello, guys. The module is great! it simplifies a lot of stuff. I have a question about saving data. So, when do we save data? Do we save it after every operation(add, remove stuff, etc.), or do we save it after player leaves. As I have an InventoryManager which would (hopefully) do all add and remove items, should add a saving method to save to the Profile at the end of each method or should I just save the whole inventory when players leave?

The module handles saving for you. Only use :Save() for cases such as developer product purchases

Though if you mean serializing data into the profile, you should make sure it is always synced at all times

1 Like

I been experimenting with it and have seen a weird case. I already have a working inventory with hardcoded values for Inventory table. After i set up ProfileService, I tried to pass The Inventory Table (with items)that I set up with ProfileService and use it instead of hardcoded Inventory table. it gives me the error “DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. API: UpdateAsync, Data Store: Testing”, but when I shallow copy the Inventory table, it works fine.

this gives me error

local copiedTable = svInventorytables in the inventory

this works well for me

local copiedTable = table.clone(svInventory)

This is the Inventory table that I set up with Profile Service

local Inventory = {
	items = { 
		{ name = "Sword", type = "Weapon", bStackable = false, quantity = 2 },
		{ name = "Axe", type = "Weapon", bStackable = false, quantity = 1 },
		{ name = "LeopardFruit", type = "Fruit", bStackable = false, quantity = 1 },
		{ name = "LeopardFruit", type = "Fruit", bStackable = false, quantity = 1 },

		-- Add more items as needed
	},
	-- could be other stuff beside items. Right now, items is good
}