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)
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)