Here the error : 21:15:05.226 - ServerScriptService.SaveData:10: attempt to index number with 'Value'
And 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.Strength.Value local save2 = plr.leaderstats.Money.Value 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.Strength.Value, plr.leaderstats.Money.Value}) end)
On line 05 and 06, you already retrieve the value. Numbers do not have the Value property.
Try removing the .Value properties from both of those lines.
Hello there.
Issue
You put a .Value
before the strength instance. This would not work as you'd be trying to index a number, which is the instance's value.
Recommendation
Use :GetService()
before indexing a service.
Fixed Code:
local DS = game:GetService("DataStoreService"):GetDataStore("SaveData") game:GetService("Players").PlayerAdded:Connect(function(plr) wait() local plrkey = "id_"..plr.UserId local save1 = plr.leaderstats.Strength local save2 = plr.leaderstats.Money 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.Strength.Value, plr.leaderstats.Money.Value}) end)
Please accept my answer if it helped.