Save your player data with ProfileService! (DataStore Module)

for _, truck in ipairs(truckFolder:GetChildren()) do

What exactly is truck it it a model, base part or something like a Boolean value within the truckFolder

Because with the code snippet you provided you calling the profileData so you can get the truck within the player’s data and according to the code the truckValue is a Boolean with would be loading

I am assuming that you are doing this in you DataService (you are calling profileService), so for saving it would be something like this

--- Adding the truck to the player's data
local profile = Profiles[player]
if profile and profile:IsActive() then
	profile.Data.trucks[truckName] = true
	print(player.Name .. " now owns the truck: " .. truckName)
end

If you have profile service setup correctly it should save when the players data

So I am getting the boolValue that is the datastore key and finding it in the profile but I’m also trying to update its value within the folder and in the profile.

Edit: it’s basically saving and updating the value.

Before you add it to the folder your could just update the value in the profile then you can add the value to the folder. Profile Service Saves it already all you have to do is update, you check for updates in the folder with the childadded()

I am guessing the snippet you sent is somewhere in here, where the DoSomethingWithALoadedProfile function is

(From the ProfileService Docs)

if player:IsDescendantOf(Players) == true then
            Profiles[player] = profile
            -- A profile has been successfully loaded:
            DoSomethingWithALoadedProfile(player, profile)
        else
            -- Player left before the profile loaded:
            profile:Release()
        end
1 Like

Okay thank you for your help. :slightly_smiling_face: Before I was going off what one of the YouTube tutorials that uses task.spawn function.

Having the strangest issue:

  • at seemingly random, a player’s profile will be overwritten by the blank ProfileTemplate,
  • the profile can then be filled in with new data, which will then save,
  • at seemingly random the previous - now overwritten - profile data loads back in and overwrites the new one.

This happens once a week and leaves my players confused and sad as to why their data was completely erased only to then load back in when they join the game again at some point.

Here’s a record from an affected player on August 29th at 6:59 AM:
data 29th 6-59AM

Here’s a record from roughly 30 minutes later, at 7:29 AM:
data 29th 7-29AM
(Note the lack of saved names, bounty and money)

And a record from the same day a couple hours later at 12:56 PM:
data 29th 12-56PM

From my understanding this could easily be chalked up to a data loading bug, with the player simply loading a blank local stats page without actually interfering with the datastore, but the records clearly show that data is indeed being saved to (and overwriting) the player’s profile.

It’d be helpful if you could show us how you load your players profiles and what you do with them.

not sure what your issue is, but why are you using _G, is this not in a module script, as _G was commonly used for info between scripts, but with modules, any script can require and get the profile info if you make a simple function that is returned that can give the requested profile.

I’m mostly using the default ProfileService template:

PlayerAdded
local function PlayerAdded(player,folder)
	local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId,"ForceLoad")
	if profile ~= nil then
		profile:AddUserId(player.UserId) -- GDPR compliance
		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:
			if wipe then
				player:Kick("Data saved successfully :)")
			else
				player:Kick("Something went wrong loading data! Please rejoin :D")
			end
		end)
		if player:IsDescendantOf(game.Players) == true then
			Profiles[player] = profile
			
			if profile.Data.Banned then
				if profile.Data.BannedBy then
					player:Kick("You have been banned by "..profile.Data.BannedBy..".")
				else
					player:Kick("You have been banned.")
				end
			end

			folder.FirstName.Value =  profile.Data.FirstName
			folder.LastName.Value =  profile.Data.LastName
			. . .
			
		else
			-- Player left before the profile loaded:
			profile:Release()
			if player then
				player:Kick("Something went wrong loading data! Please rejoin :D #300") 
			end
		end
	else
		-- The profile couldn't be loaded possibly due to other
		--   Roblox servers trying to load this profile at the same time:
		player:Kick("Something went wrong loading data! Please rejoin :D #200") 
	end
end
game.Players.PlayerAdded:Connect(function(plr)
	-- creating folder
	PlayerAdded(plr,folder)
	-- connecting other events for gameplay
PlayerRemoving
local function DataSaveOnExit(plr)
	local profile = Profiles[plr]
	if profile ~= nil then
		if rs.PlayerData:FindFirstChild(plr.Name) then

			profile.Data.Money = rs.PlayerData[plr.Name].Money.Value
			. . .

		end
		profile:Release()
	end
end
game.Players.PlayerRemoving:Connect(function(plr)
	DataSaveOnExit(plr)
	-- removing folder
end)

Hi, I am slightly new to this module and just wanted to ask if using a module with a ton of public functions like GiveCash or GiveItem would be a good idea or if it would be better to handle data in their respective scripts.

I ran into a problem. After publishing the game, i tried 2 accounts to join a server. then I have 1 account rejoin the same server. the data of that account is lost in the same server.

when I have 2 account quit that server, and have lost data account join a different server, data is back again. does anyone know what bug is this

Edit: I fixed it was my code that make profile take infinite loop and never release

I honestly wouldn’t usually do this, but since this post keeps getting at the top of the page, why not?

For those who are perhaps looking for an alternative, maybe check out DocumentService.

ProfileService hasn’t been updated (or at least, seems like it) for a long while.

Just finished a quick ProfileService rewrite :eyes:
The project name is “ProfileStore” which represents the top class of this module.
Majority of changes involve code and comment cleanup, variable name cleanup, an upgrade to the GlobalUpdates feature and auto-complete support.

It will be backwards compatible with the original internal DataStore schema ProfileService has been using, but the method names will be different and “MetaTags” will be removed in favor of a new property “Profile.LastSavedData”.

There also exists a rewritten version of ReplicaService that’s slightly faster and also has cleaner method names.

If there’s enough interest from the community and motivation from my side I might make an open source release of these modules with full documentation :slight_smile:

45 Likes

Sounds neat…! Looking forward to using it if released!

2 Likes

Please just update the module because everyone just wants an update.

I’d take it even without the documentation

1 Like

please release the module we havent gotten an update in over 2 years i think :pray:

1 Like

bro it’s probably the most used datastore module ever made.

yes, the community is interested. let’s just uhhh skip on past that hype train and get to the part where you release it. pleaseee!!! :smiley:

2 Likes

+1 to the community interest for a release

1 Like

would be awesome to see an upgraded profileservice! interested to see what specific changes were made :eyes:

1 Like

Please add support for typechecking! :pray:

2 Likes