-- Here is the code! It gets to get stone save but the value doesnt work and it doesnt save it -- saves the cash tho
local dataStoreService = game:GetService("DataStoreService"):GetDataStore("KennyGumphaDaBest33333")
game.Players.ChildAdded:connect(function(plr)
wait()
local PlayerStats = Instance.new("Folder",plr)
PlayerStats.Name = "PlayerStats"
local Cash = Instance.new("NumberValue",PlayerStats)
Cash.Name = "Cash"
Cash.Value = 2500
local stone = Instance.new("NumberValue",PlayerStats)
stone.Name = "Stone"
stone.Value = 50
print"Got Stone Value"
local key = 'id-'..plr.userId
local getsaveddata = dataStoreService:GetAsync(key)
if getsaveddata then
Cash.Value = getsaveddata[1]
stone.Value = getsaveddata[2]
print"GotStoneSave"
else
local saving = {Cash.Value}
print("Saving2 in progress")
local saving2 = {stone.Value}
print("Complete")
dataStoreService:SetAsync(key,saving, saving2)
print"Saved!"
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = 'id-'..plr.userId
local save = {plr.PlayerStats.Cash.Value}
local save2 = {plr.PlayerStats.Stone.Value}
dataStoreService:SetAsync(key,save, save2)
print("DataStore Activated")
end)
✓ ANSWER ACCEPTED
DataStore will not work I need help!? QUICK
1 answer
✓ Accepted answer
You're attempting to save 'save2' as a third argument for the SetAsync function. The SetAsync function only takes in two arguments: The key and the value to save.
If you save it all to the same table, and reference it from the same table, you should be good.
Dictionaries are useful for organizing your DataStores.
local ds = game:GetService("DataStoreService"):GetDataStore("KennyGumphaDaBest33333")
game.Players.PlayerAdded:connect(function(plr)
local key = 'id-'..plr.userId
local PlayerStats = Instance.new("Folder",plr)
PlayerStats.Name = "PlayerStats"
local Cash = Instance.new("NumberValue",PlayerStats)
Cash.Name = "Cash"
Cash.Value = 2500
local stone = Instance.new("NumberValue",PlayerStats)
stone.Name = "Stone"
stone.Value = 50
local data = ds:GetAsync(key)
if data then
Cash.Value = data.Cash
stone.Value = data.Stone
else
Cash.Value = 0
stone.Value = 0
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = 'id-'..plr.userId
local save = {
["Cash"] = plr.PlayerStats.Cash.Value;
["Stone"] = plr.PlayerStats.Stone.Value;
}
ds:SetAsync(key,save)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
