Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Leaderboard wont save?

Asked by 4 years ago

This is my code it never saves?

    local datastore = game:GetService("DataStoreService")

local ds1 = datastore:GetDataStore("LevelSaveSystem")

local ds2 = datastore:GetDataStore("CashSaveSystem")

local ds3 = datastore:GetDataStore("RubySaveSystem")



game.Players.PlayerAdded:Connect(function(plr)

local folder = Instance.new("Folder", plr)

folder.Name = "leaderstats"

local level = Instance.new("IntValue", folder)

level.Name = "Level"

local cash = Instance.new("IntValue", folder)

cash.Name = "Cash"

local ruby = Instance.new("IntValue", folder)

ruby.Name = "Ruby's"



level.Value = ds1:GetAsync(plr.UserId) or 0

ds1:SetAsync(plr.UserId, level.Value)

cash.Value = ds1:GetAsync(plr.UserId) or 10

ds2:SetAsync(plr.UserId, cash.Value)

ruby.Value = ds1:GetAsync(plr.UserId) or 0

ds3:SetAsync(plr.UserId, ruby.Value)

end)



game.Players.PlayerRemoving:Connect(function()

ds1:SetAsync(game.player.UserId, game.player.leaderstats.level.value)

ds2:SetAsync(game.player.UserId, game.player.leaderstats.cash.value)

ds3:SetAsync(game.player.UserId, game.player.leaderstats.ruby.value)

end)
0
Do you mean your leaderstats won't save? Ryanrecker2 2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
local data = game:GetService("DataStoreService")
local InStudio = game:GetService("RunService"):IsStudio()
local cash = data:GetDataStore("save1")
local ruby = data:GetDataStore("save2")
local level = data:GetDataStore("save3")
game.Players.PlayerAdded:connect(function(player)
if not InStudio then
local userid = player.UserId
local key = userid
local savegame1 = cash:GetAsync(userid)
local savegame2 = ruby:GetAsync(userid)
local savegame3 = level:GetAsync(userid)
player.leaderstats.Cash.Value = savegame1 or 0
player.leaderstats.Level.Value = savegame2 or 1
player.leaderstats.Ruby.Value = savegame3 or 0
  end end)
game.Players.PlayerRemoving:Connect(function(player)
if not InStudio then
cash:SetAsync(player.UserId,player.leaderstats.Cash.Value)
level:SetAsync(player.UserId,player.leaderstats.Level.Value)
ruby:SetAsync(player.UserId,player.leaderstats.Ruby.Value)
end end)

kuy

Ad

Answer this question