So im trying to save multiple values with profile service and replica service
but instead of getting my 12 values its only getting the same 1 for each of them.
What I mean by this is down below whenever I click the part to increase my Beli it also increases my Health which I do not want. I did not reference Health in the script below so I dont know how it can be increasing that as well
DataManager Module Code Down Below.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ProfileService = require(ServerStorage.ProfileService)
local ReplicaService = require(ServerScriptService.ReplicaService)
local CashProfileStore = ProfileService.GetProfileStore("CashProfileStore",{
Health = 100;
Stamina = 100;
Defense = 5;
Melee = 10;
Sword = 10;
DevilFruit = 0;
Level = 1;
maxLevel = 100;
Beli = 0;
Exp = 0;
ExpNeed = 0;
Points = 0;
})
local Profiles = {}
local DataReplicas = {}
local DataManager = {}
local function OnPlayerAdded(player)
local PlayerProfile = CashProfileStore:LoadProfileAsync("CashProfileStore"..player.UserId,"ForceLoad")
if PlayerProfile ~= nil then
PlayerProfile:ListenToRelease(function()
Profiles[player] = nil
DataReplicas[player] = nil
DataReplicas[player]:Destroy()
end)
if player:IsDescendantOf(Players) then
Profiles[player] = PlayerProfile
local DataReplica = ReplicaService.NewReplica({
ClassToken = ReplicaService.NewClassToken("DataToken_"..player.UserId), -- since a player's user id is unique, we will name it according to their user id to create a unique name for the class token.
Data = PlayerProfile.Data,
Replication = player -- this player that joined the game can only access to this replica!
})
DataReplicas[player] = DataReplica
else
PlayerProfile:Release()
end
else
player:Kick("Unable to load your data. Please rejoin.")
end
end
local function OnPlayerRemoved(player)
local PlayerProfile = Profiles[player]
if PlayerProfile then
PlayerProfile:Release()
end
end
function DataManager:GetData(player)
local PlayerProfile = Profiles[player]
if PlayerProfile then
return PlayerProfile
else
warn("[DataManager]: CANNOT GET DATA FOM"..player.Name..".")
end
end
function DataManager:SetData(player,dataToSet : string,newDataValue)
local PlayerProfile = self:GetData(player)
local DataReplica = DataReplicas[player]
if PlayerProfile and DataReplica then
local OldDataValueType = typeof(PlayerProfile.Data[dataToSet])
if OldDataValueType == typeof(newDataValue) then
PlayerProfile.Data[dataToSet] = newDataValue
DataReplica:SetValue({"Health"}, newDataValue)
DataReplica:SetValue({"Stamina"}, newDataValue)
DataReplica:SetValue({"Defense"}, newDataValue)
DataReplica:SetValue({"Melee"}, newDataValue)
DataReplica:SetValue({"Sword"}, newDataValue)
DataReplica:SetValue({"DevilFruit"}, newDataValue)
DataReplica:SetValue({"Level"}, newDataValue)
DataReplica:SetValue({"maxLevel"}, newDataValue)
DataReplica:SetValue({"Exp"}, newDataValue)
DataReplica:SetValue({"Beli"}, newDataValue)
DataReplica:SetValue({"ExpNeed"}, newDataValue)
DataReplica:SetValue({"Points"}, newDataValue)
end
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoved)
game:BindToClose(function()
table.foreach(Players:GetPlayers(),function(_,player)
OnPlayerRemoved(player)
end)
end)
return DataManager