ProfileStore doesn't save data

I accidentally deleted the old thread, so here we go again.

I’m using ProfileStore to save data, and I’m testing it, it’s worked on my other projects that I couldn’t be bothered to finish, but that’s besides the point.

This time, it simply hasn’t worked, the data hasn’t saved, I’ve checked the official documentation from loleris, and searched far into the comments of the tutorial for it I used, nothing.

I think there’s an error in the data loading process, but I’m not exactly sure what is wrong, any help is appreciated!

The Data Initialisation script:

-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

-- ProfileStore
local ProfileStore = require(ServerScriptService.Libraries.ProfileStore)

local function GetStoreName()
	return RunService:IsStudio() and "Test" or "Live"
end

local Template = require(ServerScriptService.Data.Template)
local DataManager = require(ServerScriptService.Data.DataManager)

-- Access profile store
local PlayerStore = ProfileStore.New(GetStoreName(), Template)

-- Add leaderstats and sync player data
local function Initialise(player: Player, profile: typeof(PlayerStore:StartSessionAsync()))

	-- Leaderstats
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"

	local Fruits = Instance.new("IntValue")
	Fruits.Name = "Fruits"
	Fruits.Value = profile.Data.Fruits
	Fruits.Parent = leaderstats

	local Talents = Instance.new("IntValue")
	Talents.Name = "Talents"
	Talents.Value = profile.Data.Talents
	Talents.Parent = leaderstats

	leaderstats.Parent = player

	-- Sync player data
	ReplicatedStorage.Events.UpdateFruits:FireClient(player, profile.Data.Fruits)
	ReplicatedStorage.Events.UpdateTalents:FireClient(player, profile.Data.Talents)
end

-- Creates and stores a profile
local function PlayerAdded(player: Player)

	-- Start a new profile session
	local profile = PlayerStore:StartSessionAsync("Player_" .. player.UserId, {
		Cancel = function()
			return player.Parent ~= Players
		end,
	})

	-- Sanity check to ensure profile exists
	if profile ~= nil then
		profile:AddUserId(player.UserId) -- GDPR compliance
		profile:Reconcile() -- Fill in missing data variables from template

		-- Handles session-locking
		profile.OnSessionEnd:Connect(function()
			DataManager.Profiles[player] = nil
			player:Kick("Data error occurred, please rejoin!")
		end)

		-- Save profile for later use
		if player.Parent == Players then
			DataManager.Profiles[player] = profile
			Initialise(player, profile)
		else
			profile:EndSession()
		end
	else
		-- Server shuts down while player is joining
		player:Kick("Data error occurred, please rejoin!")
	end
end

-- Early joiners check
for _, player in Players:GetPlayers() do
	task.spawn(PlayerAdded, player)
end

Players.PlayerAdded:Connect(PlayerAdded)

Players.PlayerRemoving:Connect(function(player: Player)
	local profile = DataManager.Profiles[player]

	if not profile then
		return
	end

	profile:EndSession()
	DataManager.Profiles[player] = nil
end)

Also, if there aren’t problems with this script, I’ll supply the other ones too.

EDIT: I’ve tried debugging the script, I think something is going on with requiring the Template. Is there something wrong with the data or is it just my Initialise script?

The Template module script:

return {
	Fruits = 350,
	Talents = 1000,
	
	Equipment = {
		Basket = "Basket",
		Picker = "Picker",
	},
	
	PickerModifications = {},
	
	Inventory = {},
}

same problem ig roblox api services is down

Maybe this is a completly dumb question, but do you have api services on?

2 Likes

Yeah, the API services are on and I’ve published the game.

I’ve tried debugging the script, I think something is going on with requiring the Template. Is there something wrong with the data or is it just my Initialise script?

The Template module script:

return {
	Fruits = 350,
	Talents = 1000,
	
	Equipment = {
		Basket = "Basket",
		Picker = "Picker",
	},
	
	PickerModifications = {},
	
	Inventory = {},
}

I don’t use values with ProfileStore, but don’t you have to update the profile whenever one of the Values changes? I don’t know for sure since I only just started using it and am using Replica instead of values, but I doubt that ProfileStore does that on its own?

To clarify: I mean that when for example the Fruits IntValue’s value changes, you would have to do

profile.Data.Talents = Talents.Value