local DSService = game:GetService("DataStoreService"):GetDataStore("Currency") local Saving = 0 game:BindToClose(function() repeat wait() until Saving <= 0 end) game:GetService("Players").PlayerAdded:connect(function(plr) local leader = Instance.new("Folder",plr) leader.Name = "leaderstats" local Credits = Instance.new("IntValue",leader) Credits.Name = "Credits" local Diamonds = Instance.new("IntValue",leader) Diamonds.Name = "Diamonds" local savedData = DSService:GetAsync(plr.UserId.."-Currency") if savedData then Credits.Value = savedData[1] Diamonds.Value = savedData[2] else local values = {Credits.Value, Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency",values) end end) game:GetService("Players").PlayerRemoving:connect(function(plr) Saving = Saving + 1 local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave) Saving = Saving - 1 end)
Try using pcall
. Also please do not use Instance.new
with parent parameter, it's deprecated. Same with connect
, use Connect
instead.
Marked as Duplicate by arshad145, User#21908, and User#19524
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?