Can you help with sharing data stores between places?
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:
001 | local dataStoreService = game:GetService( "DataStoreService" ):GetDataStore( "Deaths" ) |
002 | local ODS = game:GetService( "DataStoreService" ):GetOrderedDataStore( "WinsFixed" ) |
003 | local globalDataStoreService = game:GetService( "DataStoreService" ):GetGlobalDataStore() |
007 | local Pages = ODS:GetSortedAsync( false , 10 ) |
008 | local Data = Pages:GetCurrentPage() |
009 | local GUI 1 = game.StarterGui.LeaderboardUI |
010 | local GUI 2 = game.StarterGui.LeaderboardUI 1 |
013 | local player = game.Players:GetPlayerFromCharacter(object) |
014 | if player ~ = nil then |
015 | local ls = player:WaitForChild( "leaderstats" ) |
016 | local sl = game.Workspace:FindFirstChild(ls.Stage.Value) |
017 | object.UpperTorso.CFrame = object.UpperTorso.CFrame + Vector 3. new( 0 , 3 , 0 ) |
019 | object.UpperTorso.CFrame = sl.CFrame + Vector 3. new( 0 , 3 , 0 ) |
023 | local player = game.Players:GetPlayerFromCharacter(object) |
024 | if object.className = = "Player" then |
025 | local ack = Instance.new( "IntValue" ) |
027 | ack.Name = "leaderstats" |
030 | local ack 2 = Instance.new( "IntValue" ) |
035 | local ack 100 = Instance.new( "Folder" ) |
036 | ack 100. Name = "winstats" |
037 | ack 100. Parent = object |
039 | local ack 101 = Instance.new( "NumberValue" ) |
041 | ack 101. Parent = ack 100 |
044 | local ack 3 = Instance.new( "IntValue" ) |
046 | ack 3. Value = dataStoreService:GetAsync(object) |
048 | object.CharacterAdded:Connect( function (Character) |
050 | Character:WaitForChild( "Humanoid" ).Died:Connect( function () |
053 | ack 3. Value = ack 3. Value + 1 |
057 | local Cash = Instance.new( "IntValue" ) |
059 | Cash.Value = globalDataStoreService:GetAsync(object.UserId) or 0 |
064 | for i,v in pairs (game.Players:GetPlayers()) do |
065 | if v:FindFirstChild( "leaderstats" ) then |
066 | v.leaderstats [ currencyname ] .Value = v.leaderstats [ currencyname ] .Value + amount |
072 | game.Players.PlayerRemoving:Connect( function (plr) |
073 | local Points = plr.winstats.Wins |
074 | local Dead = plr.leaderstats.Deaths |
075 | local Money = plr.leaderstats.Cash |
078 | ODS:IncrementAsync(plr.Name,Points.Value) |
080 | dataStoreService:SetAsync(plr.UserId, Dead.Value) |
082 | globalDataStoreService:SetAsync(plr.UserId, Money.Value) |
087 | local function Update() |
088 | local succ,err = pcall ( function () |
089 | local Template = GUI 1. Template |
090 | for i,v in pairs (GUI 1. MainFrame:GetChildren()) do |
091 | if v:IsA( "Frame" ) then |
095 | local Template 2 = GUI 2. Template |
096 | for i,v in pairs (GUI 2. MainFrame:GetChildren()) do |
097 | if v:IsA( "Frame" ) then |
101 | for a,k in pairs (Data) do |
102 | local PlayerName = k.key |
103 | local PlayerPoints = k.value |
104 | local NewTemp = Template:Clone() |
105 | NewTemp.Name = PlayerName |
106 | NewTemp.FrameName.Text = PlayerName |
107 | NewTemp.FrameValue.Text = PlayerPoints |
108 | NewTemp.Visible = true |
109 | NewTemp.Parent = GUI 1. MainFrame |
110 | NewTemp:Clone().Parent = GUI 2. MainFrame |
114 | warn( "An error has occurred when trying to update leaderboard: " .. err) |
129 | game.Players.ChildAdded:Connect(oe) |
130 | game.Workspace.ChildAdded:Connect(oa) |