Hello,
I have multiple games, each with a cash leaderboard. I have tried to make it, so when someone leaves the game with cash and deaths, it saves their amount of cash and deaths and then allows the other games to load and save over that value. I don't know if its possible. Can you help?
I do not want to save the variable Stage in any way.
Here is my code so far from ServerScriptStorage:
local dataStoreService = game:GetService("DataStoreService"):GetDataStore("Deaths")
local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("WinsFixed")
local globalDataStoreService = game:GetService("DataStoreService"):GetGlobalDataStore()
amount = 1
timedelay = 40
currencyname = "Cash"
local Pages = ODS:GetSortedAsync(false,10)
local Data = Pages:GetCurrentPage()
local GUI1=game.StarterGui.LeaderboardUI
local GUI2=game.StarterGui.LeaderboardUI1
function oa(object)
local player = game.Players:GetPlayerFromCharacter(object)
if player ~= nil then
local ls = player:WaitForChild("leaderstats")
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
object.UpperTorso.CFrame = object.UpperTorso.CFrame + Vector3.new(0,3,0)
wait()
object.UpperTorso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end
end
function oe(object)
local player = game.Players:GetPlayerFromCharacter(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
ack.Parent = object
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
local ack100 = Instance.new("Folder")
ack100.Name = "winstats"
ack100.Parent = object
local ack101 = Instance.new("NumberValue")
ack101.Name = "Wins"
ack101.Parent = ack100
local ack3 = Instance.new("IntValue")
ack3.Name = "Deaths"
ack3.Value = dataStoreService:GetAsync(object)
ack3.Parent = ack
object.CharacterAdded:Connect(function(Character)
local d = true
Character:WaitForChild("Humanoid").Died:Connect(function()
if (d) then
d = false
ack3.Value = ack3.Value + 1
end
end)
end)
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = globalDataStoreService:GetAsync(object.UserId) or 0
Cash.Parent = ack
while true do
wait(timedelay)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") then
v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
end
end
end
end
end
game.Players.PlayerRemoving:Connect(function(plr)
local Points = plr.winstats.Wins
local Dead = plr.leaderstats.Deaths
local Money = plr.leaderstats.Cash
if Points then
print("saved")
ODS:IncrementAsync(plr.Name,Points.Value)
dataStoreService:SetAsync(plr.UserId, Dead.Value)
globalDataStoreService:SetAsync(plr.UserId, Money.Value)
end
end)
local function Update()
local succ,err = pcall(function()
local Template = GUI1.Template
for i,v in pairs(GUI1.MainFrame:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
local Template2 = GUI2.Template
for i,v in pairs(GUI2.MainFrame:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
for a,k in pairs(Data) do
local PlayerName = k.key
local PlayerPoints = k.value
local NewTemp = Template:Clone()
NewTemp.Name = PlayerName
NewTemp.FrameName.Text = PlayerName
NewTemp.FrameValue.Text = PlayerPoints
NewTemp.Visible = true
NewTemp.Parent = GUI1.MainFrame
NewTemp:Clone().Parent = GUI2.MainFrame
end
end)
if err then
warn("An error has occurred when trying to update leaderboard: " .. err)
end
end
Update()
spawn(function()
while wait(60*3) do
Update()
end
end)
game.Players.ChildAdded:Connect(oe)
game.Workspace.ChildAdded:Connect(oa)

3 comments
This post shows how to do it: https://devforum.roblox.com/t/using-google-spreadsheets-as-a-database/12658
Actually, GlobalDataStore can be helpful, here's the link; http://wiki.roblox.com/index.php?title=API:Class/GlobalDataStore
I have looked into to using GlobalDataStores, but I can't get them to work. Can you modify the code attached to make it work?