I am trying to get a Datastore. and when i try this:
local ds = game:GetService("DataStoreService"):GetDataStore("datastore") --not my real datastore name. just for privacy game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats.currentTime --Change to your stat local save2 = plr.leaderstats.maxTime local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] else local NumberForSaving = {save1.Value, save2.Value} ds:GetAsync(plrkey, NumberForSaving) end end) game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId, {plr.leaderstats.currentTime.Value, plr.leaderstats.maxTime.Value}) end)
i get this error: 16:06:59.632 currentTime is not a valid member of Folder "Players.Sivan12345678.leaderstats"
please help :-:
You either haven't made currentTime or you have to wait for it to be there.
local ds = game:GetService("DataStoreService"):GetDataStore("datastore") --not my real datastore name. just for privacy game.Players.PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.userId local save1 = plr.leaderstats:WaitForChild("currentTime") --Change to your stat local save2 = plr.leaderstats.maxTime local GetSaved = ds:GetAsync(plrkey) if GetSaved then save1.Value = GetSaved[1] save2.Value = GetSaved[2] else local NumberForSaving = {save1.Value, save2.Value} ds:GetAsync(plrkey, NumberForSaving) end end) game.Players.PlayerRemoving:Connect(function(plr) ds:SetAsync("id_"..plr.userId, {plr.leaderstats.currentTime.Value, plr.leaderstats.maxTime.Value}) end)
You need to create a new string value into leaderstats using a function called Instance.new
as you do not have any variables inside of the leaderstats folder.