Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Saving leaderstats failing again?

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)

5 comments

0

Just a suggestion, I suggest you save the values as a table, so you don't have to keep putting set async

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

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

0

And I dont know how to make it a table

0

i sent you a message

1 answer

✓ Accepted answer

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)

7 comments

0

Thank you I will test this out and accept it if it works

0

In studio lines 32-35 say "Unknown global "Money","Ruby","Crate

0

"Crate" and "maxamount"

0

In studio lines 32-35 say "Unknown global "Money","Ruby","Crate

0

I edit it

0

ummm I miss the word player because it cant be value without parent

0

go to the script and copy again and sure 100% perfect and plsss accept if its works

This discussion is preserved as it was. New answers, comments, and votes are closed.