Save your player data with ProfileService! (DataStore Module)

Couldn’t this be extended to use MemoryDatastore for caching with session locks that don’t always have to use datastores?

This is what loleris said while ago.

2 Likes

I second this. ProfileService on the Wally Package Manager by Uplift Games would help out a ton of developers using the Wally/Rojo Workflow. @loleris Please consider uploading ProfileService as a package on wally :pray:

5 Likes

My game has way too many data lines stored and I might be unable to store anymore values, how would I fix this?

How do I go about adding a new value to a profile without messing with data.
image
I am adding levels to my game and need to make it save with profile service, while not messing with my other values.

“levels” is currently nil, and I can check if it is nil with an if statement. Where do I go from after confirming that it is nil, so it saves the levels and doesnt end up with this error:
image

store shorkt key values together
example time played
–A most efficient (least fun to access trough code)

Timeplayed = {Dagger,Hellion,BoStaff}
Timeplayed = {100,2000,4000}

and access them by Timeplayed[1],Timeplayed[2],Timeplayed[3],
–example B easier to code with but less efficient cause u storing unusfull names that u don’t need
or Timeplayed = {["Dagger"]=100,["Hellion"]=2000,["BoStaff"]=4000}
this way u can fit more just dont exceed the key value limit

1 Like

does profiler service have check to see if datastore is offline on roblox?
if not i have to add my own just wondering

example datastore is offline player joins it might think its a new player cause no profile
then he leaves datastore back online and it save it as a new player over the old one

if its not added then i would prob check with vanilla datastore check if the datastore “game” has a key called “StoreOnline” value “yes”

before i load player profile i check if the key StoreOnline is found if not datastore offline and don’t load nor save

if it is found then if profile not found its new player

but i might not need this at all if it is already build into profiler service just askin if it is bacause can’t seem to find anything about it being mentioned

Of course it has these checks to prevent your data from being corrupted.

1 Like

ok nice then i don’t have to check myself awsome

does anyone know how i can load a profile withoud a player being online or point me in the right way i am making an admin tool that can local change players data wich work but i also have a toggle to do it directly in the datastore if there offline
but going over the code im getting confused with the profile release and stuff

local Players = game:GetService("Players")

local ProfileService = require(game.ServerScriptService.PlayerData.ProfileService)
local ProfileTemplate = require(game.ServerScriptService.PlayerData.ProfileTemplate)

local ProfileStore = ProfileService.GetProfileStore(
	game.ServerStorage.Settings.DataStorePrefix.Value,
	ProfileTemplate
)

local Profiles = {}


local function onPlayerAdded(player)
	local profile = ProfileStore:LoadProfileAsync(
		"Player_" .. player.UserId,
		"ForceLoad"
	)

	if profile then
		profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick("A1")
		end)

		if player:IsDescendantOf(Players) then
			Profiles[player] = profile
		else
			profile:Release()
		end
	else
		player:Kick("A2")
	end
end

local function onPlayerRemoving(player)
	local profile = Profiles[player]
	if profile then
		require(game.ServerScriptService.PlayerData.Save).skill(require(game.ServerScriptService.Var),player)
		profile:Release()
		print("saved player",player,profile)
	end
end


Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)

local DataManager = {}

function DataManager:Get(player)
	local profile = Profiles[player]

	if profile then
		return profile.Data
	end
end

return DataManager

any ideas how i convert this to also work with loading someone elses profile so i can edit it
it also seems to require an player object i only have a player id to work with if hes offline

Hi, I’m new to using ProfileService. Is there an open source wrapper over ProfileService? If not, is there a reason why not? like - are wrappers meant to be game-specific in terms of their interface (i.e. Wrapper.addCoins) - or are they just so simple that it doesn’t make sense for one to be released open source? or has just nobody bothered

There’ve been a few wrappers and none of them provide much useful functionality and just unnecessarily abstract ProfileService’s easy to understand API - hence why they’re barely used since their API is very bloated.

Thanks for the reply! Would you know of any examples for me to take a look at?

I made this module a while back but never published it:

local profileModule = require(...) --> path here
local template = {}
local profiles = profileModule.new("save",template)

methods.ProfileLoaded:Connect(function(player,profile)
--- that's it! the table passed as profile can be changed and it'll save
end)

Is this what you were referring to?

1 Like

+1 For Wally support if possible :slight_smile:

4 Likes

(Outdated)

5 Likes

How would this work? Wouldnt the table just be the second line as your just restating the value, so I wouldn’t be able to get one of the timeplayed of a certain weapon, because it’s just a number?

Hello! I used the Updated profileserive with my new game but I’ve experienced and got reported about data not loading sometimes when a player joins the game. It takes a very long time to load which breaks the whole game and I want to know if anyone else is having this issue as well? I’ve used the same datastore module that was shown in “EncodedLua” video. Personally I know nothing about datastores but profileservice helped me a tun.

Question: Is there a client checker I’m suppose to be doing to wait until data is loaded? It only breaks the client when data ain’t loaded in before client

My game: 🦩SUMMER🦩Throwing Simulator 🔥 - Roblox

I’ve had this issue as well. Sometimes it doesn’t seem to save my profile and undo the session lock.

1 Like

DataStore requests are not instant and sometimes they can take several seconds to complete. If a player is hoping between sessions that can take ProfileService up to like 14 seconds to resolve at times, but usually it can still be pretty fast.

However, if you fail to release the profile after every time a player leaves you’re going to see incredibly long load times, but I doubt it’s something you’re dealing with.

I tried joining your game and it seems to work fine - you should probably work on postponing the client from starting before server loads the data.

6 Likes