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

Saving leaderstats failing again?

Asked by
Vxpper 101
4 years ago

Whether I buy a developer product, add or subtract money with the server my money will stay at the same amount, what have I done wrong?

local datastore = game:GetService("DataStoreService")
local MyMoney = datastore:GetDataStore("MoneyData")
local MyRuby = datastore:GetDataStore("RubyData")
local MyCrates = datastore:GetDataStore("CrateData")
local Mymaxamnt = datastore:GetDataStore("MaxAmountData")
local bsnss = datastore:GetDataStore("BusinessOwned")

game.Players.playerAdded:connect(function(player)
    local Money = Instance.new("IntValue", player)
    Money.Name = "Money"
    local Ruby = Instance.new("IntValue", player)
    Ruby.Name = "Rubys"
    local Crate = Instance.new("IntValue", player)
    Crate.Name = "Crates"
    local maxamount = Instance.new("IntValue", player)
    maxamount.Name = "MaxAmount"

    Money.Value = MyMoney:GetAsync(player.UserId)
    MyMoney:SetAsync(player.UserId, Money.Value)
    Ruby.Value = MyRuby:GetAsync(player.UserId)
    MyRuby:SetAsync(player.UserId, Ruby.Value)
    Crate.Value = MyCrates:GetAsync(player.UserId)
    MyCrates:SetAsync(player.UserId, Crate.Value)
    maxamount.Value = Mymaxamnt:GetAsync(player.UserId)
    Mymaxamnt:SetAsync(player.UserId, maxamount.Value)

game.Players.PlayerRemoving:connect(function(player)
    MyMoney:SetAsync(player.UserId, Money.Value)
    MyRuby:SetAsync(player.UserId, Ruby.Value)
    MyCrates:SetAsync(player.UserId, Crate.Value)
    Mymaxamnt:SetAsync(player.UserId, maxamount.Value)
    end)
end)
0
Just a suggestion, I suggest you save the values as a table, so you don't have to keep putting set async HomieFirePGN 137 — 4y
0
Also, are you changing the values with a script, or manually? Because for some reason, if you change it manually, those changed stuff won't be saved HomieFirePGN 137 — 4y
0
I've saved through a script, but i tested the game with my friend and our values for money and rubys are combining, i had 5k rubys and he had 0 i rejoined and had 0 rubys and 950,000 cash when i only had 530,000 before Vxpper 101 — 4y
0
And I dont know how to make it a table Vxpper 101 — 4y
0
i sent you a message gueli844 -1 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You can use pcall function. The pcall functions make holds an error. And saves no worries. Script

local datastore = game:GetService("DataStoreService")
local MyMoney = datastore:GetDataStore("MoneyData")
local MyRuby = datastore:GetDataStore("RubyData")
local MyCrates = datastore:GetDataStore("CrateData")
local Mymaxamnt = datastore:GetDataStore("MaxAmountData")
local bsnss = datastore:GetDataStore("BusinessOwned")

game.Players.playerAdded:connect(function(player)
    local Money = Instance.new("IntValue", player)
    Money.Name = "Money"
    local Ruby = Instance.new("IntValue", player)
    Ruby.Name = "Rubys"
    local Crate = Instance.new("IntValue", player)
    Crate.Name = "Crates"
    local maxamount = Instance.new("IntValue", player)
    maxamount.Name = "MaxAmount"

   pcall(function()
    Money.Value = MyMoney:GetAsync(player.UserId)
    MyMoney:SetAsync(player.UserId, Money.Value)
    Ruby.Value = MyRuby:GetAsync(player.UserId)
    MyRuby:SetAsync(player.UserId, Ruby.Value)
    Crate.Value = MyCrates:GetAsync(player.UserId)
    MyCrates:SetAsync(player.UserId, Crate.Value)
    maxamount.Value = Mymaxamnt:GetAsync(player.UserId)
    Mymaxamnt:SetAsync(player.UserId, maxamount.Value)
   end)
end)

game.Players.PlayerRemoving:connect(function(player)
    pcall(function()
    MyMoney:SetAsync(player.UserId, player.Money.Value)
    MyRuby:SetAsync(player.UserId, player.Ruby.Value)
    MyCrates:SetAsync(player.UserId, player.Crate.Value)
    Mymaxamnt:SetAsync(player.UserId, player.maxamount.Value)
    end)
end)
0
Thank you I will test this out and accept it if it works Vxpper 101 — 4y
0
In studio lines 32-35 say "Unknown global "Money","Ruby","Crate Vxpper 101 — 4y
0
"Crate" and "maxamount" Vxpper 101 — 4y
0
In studio lines 32-35 say "Unknown global "Money","Ruby","Crate Vxpper 101 — 4y
View all comments (3 more)
0
I edit it robloxsario 76 — 4y
0
ummm I miss the word player because it cant be value without parent robloxsario 76 — 4y
0
go to the script and copy again and sure 100% perfect and plsss accept if its works robloxsario 76 — 4y
Ad

Answer this question