It can start tricky but when you learn it it seems so easy. litteraly all you need to worry about is setting and getting.
game:GetService("DataStoreService")
game:GetService("DataStoreService"):GetDataStore("name of datastore")
game:GetService("DataStoreService"):GetDataStore("name of datastore"):SetAsync()
game:GetService("DataStoreService"):GetDataStore("name of datastore"):GetAsync()
game:GetService("DataStoreService"):GetDataStore("name of datastore"):SetAsync(Key,Value)
game:GetService("DataStoreService"):GetDataStore("name of datastore"):GetAsync(Key)
game:GetService("DataStoreService"):GetDataStore("name of datastore"):SetAsync("Row1","true")
if game:GetService("DataStoreService"):GetDataStore("name of datastore"):GetAsync("Row1") == "true" then
print hi
easy set and get.
this is example script for when you press button it toggles(switches between two) two values.
game:GetService("DataStoreService"):GetDataStore("Toggle"):SetAsync("trueORfalse","true")
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("DataStoreService"):GetDataStore("Toggle"):GetAsync("trueORfalse") == "true" then
game:GetService("DataStoreService"):GetDataStore("Toggle"):SetAsync("trueORfalse","false")
elseif game:GetService("DataStoreService"):GetDataStore("Toggle"):GetAsync("trueORfalse") == "false then"
game:GetService("DataStoreService"):GetDataStore("Toggle"):SetAsync("trueORfalse","true")
end
end)
and keeps going on forever. So now to answer your question.
DS = game:GetService("DataStoreService"):GetDataStore("SaveNeedData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
points = plr.Stats.Pyramids
rebirths = plr.Stats.Prestiges
if DS:GetAsync(plr.userId) == nil then
points.Value = DS:GetAsync(plr.userId)[1]
rebirths.Value = DS:GetAsync(plr.userId)[2]
else
NumbersForSaving = {points.Value, rebirths.Value}
DS:SetAsync(plr.userid, NumbersForSaving)
end
while wait() do
DS:SetAsync(plr.userId, {plr.Stats[2].Value, plr.Stats[1].Value})
end
end)
Changes Are:
Dont Put Local, its just a pain. theres no need to anyway, its code that only works for a block of code
Always press enter(put empty line) between setting values and the actual code
You use too many values, only set important one with not enough room to fit on whole line, like a=12, that is short, that does not need to be a set value, just say blahblah(12)
You dont even need the "id_".., just put plr.userid, but its probably too late because you most likely already created this datastore, just dont put extra stuff in for the future. thats why i directly put it userid
i changed get async to set because there were two variables there for get, get can only be one, get is for checking so after it you put == something.
and you cant put two variables in one variable, i saw that- you made NumberForSaving = (variable1, variable2), and you made that into ONE variable which is NumberForSaving and put it in SetASync(plr.userid,NmbersforSaving),so basically, thats saying this: SetAsync(38726,pointsvalue,rebirtsvalue)THATS THREE VARIABLES. thats why it saves one, it has to store that second variable, so the way it does it is by setting that datastore using the FIRST ONE, which is points.Value. instead of this change it one more time to make two parts, rebirth and points. wo make that script this:
if DS:GetAsync(plr.userId) == nil then
points.Value = DS:GetAsync(plr.userId)[1]
rebirths.Value = DS:GetAsync(plr.userId)[2]
else
DS:SetAsync(plr.userid.."points", points.Value)
DS:SetAsync(plr.userid.."rebirths", rebirths.Value)
end
end)
but do whatever you want
2 comments
You're not a bad programmer! Datastore can definitely be tricky. I encourage you to post your code here so we can see what needs to be fixed and explain what we changed.
k then