Hey there!
I have been having trouble saving values using data store 2, I am trying to save multiple values at once and the output is saying that it is saving but it is not. SaveInStudio is true.
Here is my leaderstat script:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Cash = Instance.new("IntValue")
Cash.Parent = leaderstats
Cash.Name = "Cash"
local Wins = Instance.new("IntValue")
Wins.Parent = leaderstats
Wins.Name = "Wins"
Here is my datastore script (It is not the same script as the leaderstats.):
local DataStore2 = require(game.ServerScriptService.ServerModules.DataStore2)
DataStore2.Combine("MasterKey", "points", "Wins")
game.Players.PlayerAdded:Connect(function(plr)
--DataStore below
local PointStore = DataStore2("points",plr)
local WinStore = DataStore2("Wins", plr)
local defaultValue = 0
local function WinUpdated(UpdatedValue)
plr.leaderstats.Wins.Value = WinStore:Get(UpdatedValue)
end
local function CashUpdated(UpdatedValue)
plr.leaderstats.Cash.Value = PointStore:Get(UpdatedValue)
end
CashUpdated(defaultValue)
WinUpdated(defaultValue)
PointStore:OnUpdate(CashUpdated)
WinStore:OnUpdate(WinUpdated)
end)
game.Workspace.CoinPart.Touched:Connect(function(hit)
if hit:FindFirstChildWhichIsA("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr .leaderstats.Cash.Value += cash
CashStore:Increment(cash, 0)
local WinStore = DataStore2("Wins", plr)
plr.leaderstats.Wins.Value += 1
WinStore:Increment(1,0)
end
end)
Thank you