hello, i've been having issues on how to save data. This is my second time using datastore so I definitely don't know what I'm doing. The error occurs at line 39, "_CENTS.Value = data[1] or 100".
local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("DataStore1")
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player ~= nil
local _CENTS = game.ServerStorage.Currencys[player.Name].Currency.Cents
local _CURRENTSTEPSTOMULTIPLIER = game.ServerStorage.Currencys[player.Name].UI_Mechanics.CurrentStepsToMultiplier
local _CURRENTENERGY = game.ServerStorage.Currencys[player.Name].UI_Mechanics.Current_Energy
local _CURRENTMULTIPLIER = game.ServerStorage.Currencys[player.Name].UI_Mechanics.Current_Multiplier
local _CURRENTSTAMINA = game.ServerStorage.Currencys[player.Name].UI_Mechanics.Current_Stamina
local _MAXENERGY = game.ServerStorage.Currencys[player.Name].UI_Mechanics.Max_Energy
local _STAMINAMAX = game.ServerStorage.Currencys[player.Name].UI_Mechanics.Stamina_Max
local _STEPSTONEXTMULTIPLIER = game.ServerStorage.Currencys[player.Name].UI_Mechanics.StepsToNextMultiplier
local valuesToSave = {_CENTS.Value,
_CURRENTSTEPSTOMULTIPLIER.Value,
_CURRENTENERGY.Value,
_CURRENTSTAMINA.Value,
_MAXENERGY.Value,
_STAMINAMAX.Value,
_STEPSTONEXTMULTIPLIER.Value,
}
local playerUserId = "player_"..player.UserId
local data -- A variable to assign the data to
--[[
load data
--]]
local success, errormessage = pcall(function()
data = DataStore1:GetAsync(playerUserId, valuesToSave)
end)
if success then
_CENTS.Value = data[1] or 100
_CURRENTSTEPSTOMULTIPLIER.Value = data[2] or 0
_CURRENTENERGY.Value = data[3] or 0
_CURRENTSTAMINA.Value = data[4] or 0
_MAXENERGY.Value = data[5] or 50
_STAMINAMAX.Value = data[6] or 100
_STEPSTONEXTMULTIPLIER.Value = data[7] or 2
elseif errormessage then
print(errormessage)
end
end)

1 comment
Thats not an datastoreservice error. Please ASK the question! btw. The error mean that the array/table/dictionary doesn't exist