(found a solution)
For some reason my Data Store script isn't working. I have checked the API Services and HTTP Requests boxes. Also the data store doesn't work not only in the studio but also in the game itself. There are no errors found aswell Please help!
Here is the script:
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.Bucks local save2 = plr.leaderstats.Character local save3 = plr.leaderstats.CA local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] save3.Value = GetSaved[3] else local NumbersForSaving = {save1.Value,save2.Value,save3.Value} ds:GetAsync(plrkey, NumbersForSaving) end end) game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Bucks.Value, plr.leaderstats.Character.Value, plr.leaderstats.CA.Value}) end)
Hello!
In line 16, do you mean :SetAsync
?
ds:GetAsync(plrkey, NumbersForSaving)
Also, I'd recommend for you to specify where the values are located in the table, example:
local foobar = { [1] = "foo", [2] = "bar" }
Here and here are developer references about datastores. Check them out sometime, to see if you can find your problem.
If you have any questions, ask them below!
I hope this helps!
Change
plr.userId
to
plr.UserId
Also
if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] save3.Value = GetSaved[3] else local NumbersForSaving = {save1.Value,save2.Value,save3.Value} ds:GetAsync(plrkey, NumbersForSaving) end
to
if GetSaved then save1.Value = GetSaved["Bucks"] save2.Value = GetSaved["Character"] save3.Value = GetSaved["CA"] else local NumbersForSaving = {save1.Value,save2.Value,save3.Value} ds:GetAsync(plrkey, NumbersForSaving) end
just put the plr parameter to player.
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData") game.Players.PlayerAdded:Connect(function(player) wait() local plrkey = "id_"..player.userId local save1 = player.leaderstats.Bucks local save2 = player.leaderstats.Character local save3 = player.leaderstats.CA local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] save3.Value = GetSaved[3] else local NumbersForSaving = {save1.Value,save2.Value,save3.Value} ds:GetAsync(plrkey, NumbersForSaving) end end) game.Players.PlayerRemoving:Connect(function(player) ds:SetAsync("id_"..player.userId, {player.leaderstats.Bucks.Value, player.leaderstats.Character.Value, player.leaderstats.CA.Value}) end)