Changing value of StringValues runtime(ProfileStore)

Hi, i made a data store script, and i stuck with a problem that i cant really modify values of StringValues runtime(because it will not replicate and just change nothing, this will not even save).
So i want to fix this problem. There is code:

local service = {}

local profileStore = require(script.Parent.ProfileStore)
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local profileTemplate = require(script.ProfileTemplate)
local dataManager = require(script.Manager)

local xpnew = Instance.new

service.GetToken = function()
	return runService:IsStudio() and "Data-Test" or "PlayerDataStore"
end

local PlayerStore = profileStore.New(service.GetToken(), profileTemplate)
local Profiles: {[player]: typeof(PlayerStore:StartSessionAsync())} = {}

local function CreateData(player : Player, Profile: typeof(PlayerStore:StartSessionAsync()))
	local config = xpnew("Folder", player.Character)
	config.Name = "Config"
	
	local armor = xpnew("Folder", config)
	armor.Name = "Armor"
	
	local armorPenetration = xpnew("StringValue", armor)
	armorPenetration.Name = "ArmorPenetration"
	armorPenetration.Value = Profile.Data.ArmorPenetration
	
	if config then
		print("Data for player is created/restored.")
	end
	
end

local function PlayerAdded(player : Player)
	local profile = PlayerStore:StartSessionAsync(`{player.UserId}`, {
		Cancel = function()
			return player.Parent ~= players
		end,
	})

	if profile ~= nil then

		profile:AddUserId(player.UserId)
		profile:Reconcile()

		profile.OnSessionEnd:Connect(function()
			dataManager.Profiles[player] = nil
			player:Kick(`Profile session end - Please rejoin`)
		end)

		if player.Parent == players then
			dataManager.Profiles[player] = profile
			CreateData(player, profile)
		
		else
			profile:EndSession()
		end

	else
		player:Kick(`Profile load fail - Please rejoin`)
	end
end

service.Connect = function()
	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 profile ~= nil then
			profile:EndSession()
		end
		
		player.CharacterAdded:Connect(function (c)
			c.Parent = workspace
		end)
	end)
end

service.Connect()

return service

I think that i can just make remote events for updating each value and Firing client. But i dont really think that this is efficient way.

Don’t mirror your stats into StringValue objects unless you really need to, you’re better off keeping them in only the server’s profile.Data and whenever a value is changed, fire a remote event to the client with that new value, or even a table of values if you need to send more player data

Unless this value is rapidly changing, this is probably the way to go

Okay i will try, so basically i dont really need these string values?. I though it would be a good idea to use it for armor/other stats

1 Like

Unless you need to use it multiple times in a local script in different places even when its unchanged, then you don’t really need to save it anywhere, just send a remote event telling the client to update it with the new value for things like UI changes, etc.

If you need to save it, then you can save it in a table on the client