How can I get profile service in a client script?

The question is literally the title.

I’m trying to get the players cash from profile service in a client script, how can I do that?

I though of sending a remote event with players cash value from a server script but doesn’t seem to work right

2 Likes

Umm, why are you using profile service?
It’s better to use Datastores.

nvm me being dumb for 10 secs

1 Like

You can’t use datastores in a client, but as you have previously tried, you can transmit the datastore data from a server script to a client script.

You can perhaps show us what you have previously tried and we can see any issues.

This problem is pretty simple to tackle. ProfileService does just about everything for you, and so long as you understand Roblox’s game model you can handle the rest.

First of all- you need to ensure that you have set ProfileService up in a way that you can easily access the information you need. Our games have used ProfileService a few times, and generally we set it up like this inside of our data module:

  1. Traditional setup of profile caching.
  2. Accessibility functions (you could just manually access player data as well- that works with modules because once they run that code will exist inside of the same code environment).
  3. Extra stuff that doesn’t matter much for this explanation.

You can access your data profiles through any script that has consistent access to a completed package reference.


Ideally you’re going to want a separate player data cache on the client. This is because constantly bombing your remote objects with requests is bad code practice and in very rare circumstances can cause your remotes to reach their thresh-hold limits.

Once you know a player either has loaded their save or default data, you can pass that table specifically through a remote and catch on the client’s end. For your own learning purposes, here’s how our code is setup inside one of our older places.

local CurrentlyCachedProfile = nil -- 47
local CachedProfileExists = false -- 48

ReplicatedStorage.FullDataUpdate.OnClientEvent:Connect(function(DataProfile, ReqXP, XPOwned, Level) -- 132

--[[
Keep in mind I have omitted unimportant lines of code.
]]

Once FullDataUpdate has become activated it will not become active again. We want to avoid sending that much information across our remotes if we can. The inside of this anonymous function will write that data to a top scope variable inside of this primary client-sided data script.

Now we have a data cache on the client, and before we constantly send requests to the server trying to verify and make purchases, we run client-side sanity checks. If these go through our remotes can become active and server-sided sanity checks etc… can take place. That’s all there is to it.

The biggest thing is to make sure you’ve set ProfileService up in an optimal and ideal way to actually work with the profiles it provides. It’s a powerful module, but if you don’t set it up correctly it becomes much harder to reap benefits from it. In our games, once our server-sided data handler notices a profile has been initially created (even if that table is filled with default data) we push this to the client so that cache can exist.

1 Like

How would you update the cache on the client after you have initially sent the data? Like say anytime the data for “Level” or something updates on the Server, how would you detect that change on the client?

could use replica, made by the same creator of profile, even has a template setup for both