My datastore script works in studio's play mode but not a live game. any ideas? [closed]
local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")
local Saving = 0
wait()
game:BindToClose(function()
repeat wait() until Saving <= 0
end)
game:GetService("Players").PlayerAdded:Connect(function(plr)
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = plr
local Credits = Instance.new("IntValue")
Credits.Name = "Credits"
Credits.Parent = leader
local Diamonds = Instance.new("IntValue")
Diamonds.Name = "Diamonds"
Diamonds.Parent = leader
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)
Closed as Not Constructive by User#20388, GreekGodOfMLG, User#21908, and Operation_Meme
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?