I want to create a easy to use maintainable data store system for my game.
The issue is that when I change one of the values in the ServerStorage.PlayersData
it doesn’t save when I quit and re-join.
local function GiveData(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
local Data = PlayersData:FindFirstChild(player.Name) or script.Data:Clone()
Data.Name = player.Name
Data.Parent = PlayersData
end
local function PlayerAdded(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile == nil then
player:Kick("Data issue, please rejoin.")
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick("Data issue, please rejoin.")
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = profile
GiveData(player)
else
profile:Release()
end
end
This GiveData
function above clones a Folder of all the data of the player into a PlayersData folder in serverstorage: here is how it looks.
local ProfileTemplate = {
PrimaryWeapon = "Sword";
PlayerBlessings = "";
PlayerSigns = "";
Kills = 0;
Kunnan = Elements[math.random(1, #Elements)];
Armor = "";
Enchant = "";
Level = 1;
AnimationStyle = "TwoHand";
Race = Races[math.random(1, #Races)];
}
This is the template of the player when they join.