Basically, I have leaderboardstats model and an IntValue in there so that money will show up on the leaderboards, but this is just for "show". The real values are to be in ReplicatedStorage. I use datastore to set the value of the replicatedstorage and it works fine, the problem is I then want the IntValue in leaderboardstats to match the IntValue in ReplicatedStorage. Here is my code
local DataStore = game:GetService("DataStoreService"):GetDataStore("data")
game.Players.PlayerAdded:connect(function(player)
local entry = player.Name
local model = Instance.new("Model", game.ReplicatedStorage)
local coins = Instance.new("IntValue", game.ReplicatedStorage.model)
coins.Name = "Coins"
local levels = Instance.new("IntValue")
levels.Parent = game.ReplicatedStorage.model
levels.Name = "XP"
model.Name = entry --This needs to be at the end
-- These next values are for the leaderboards, this is just so I don't have to make a GUI for the leaderstats, only coins and xp matter
local leaderboardstats = Instance.new("Model", player)
leaderboardstats.Name = "leaderstats"
local coins2 = Instance.new("IntValue")
coins2.Parent = leaderboardstats
coins2.Name = "Coins"
local levels2 = Instance.new("IntValue")
levels2.Parent = leaderboardstats
levels2.Name = "XP"
wait(1)
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save format: (status, xp, hp, s, etc)
coins.Value = savedValues[1] or 0
levels.Value = savedValues[2] or 0
else
local valuesToSave = {coins.Value, levels.Value}
DataStore:SetAsync(key, valuesToSave)
end
wait(1)
player.leaderstats.Coins.Value = game.ReplicatedStorage.entry.Coins.Value --Sync the Coins IntValue in ReplicatedStorage with one in leaderstats
player.leaderstats.XP.Value = game.ReplicatedStorage.entry.XP.Value -- Sync the XP IntValue in ReplicatedStorage with one in leaderstats
