Current code:
local DataStoreService = game:GetService("DataStoreService")
local HatStore = DataStoreService:GetDataStore("HatStore")
--below is inside a PlayerAdded function
local hatdata
local success, errorMessage = pcall(function()
hatdata = hatdata:GetAsync("Player_"..player.UserId)
end)
if success and hatdata then
for i, v in pairs(hatdata) do
local value = Instance.new("StringValue")
value.Name = i
value.Value = v
end
else
local currentHour = os.date("*t")["hour"]
if currentHour < 12 or currentHour == 24 then
AMIndicator = 'AM'
else
AMIndicator = 'PM'
end
LatestError.Value = "Error loading data at " .. getTime() .. " " .. AMIndicator
warn(errorMessage)
end
Datastore (named HatStore):
When a hat is unboxed, a StringValue is created in a folder named Inventory located inside the player (not character), and has the name of the hat and value of its particle effect (none if it doesn’t have an effect). After this, it puts them all into a dictionary and saves it:
local var = Instance.new("StringValue")
var.Name = hat.Name
if num == 50 then
var.Value = effect.Name
else
var.Value = "None"
end
var.Parent = script.Parent.Parent.Parent.Parent.Parent.Inventory
local invlist = {}
for i, v in pairs(script.Parent.Parent.Parent.Parent.Parent.Inventory:GetChildren()) do
invlist[v.Name] = v.Value
end
local success, errorMessage = pcall(function()
HatStore:SetAsync("Player_"..script.Parent.Parent.Parent.Parent.Parent.UserId,invlist)
end)
if not success then
local currentHour = os.date("*t")["hour"]
if currentHour < 12 or currentHour == 24 then
AMIndicator = 'AM'
else
AMIndicator = 'PM'
end
script.Parent.Parent.Parent.Parent.Parent.LatestError.Value = "Error saving data at " .. getTime() .. " " .. AMIndicator
end
and I want to be able to export those values back into the Inventory folder in the same state they were put in, but keep getting the error ServerScriptService.Script:43: attempt to index nil with 'GetAsync’
It’s probably a simple fix but I’m new to DataStores and need all the help I can get. Thanks! <3