So, I’ve been recently learning about DataStores, and I was trying to make a data store script where it would save data inside a folder that is inside the player. But, everytime I run the script, the Output comes up with: Argument 2 missing or nil. Does anyone know about what’s going on? By the way, here’s the code:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new("Folder")
Folder.Name = "Hats"
Folder.Parent = player.Head
local data
local success, errormessge = pcall(function()
data = myDataStore:GetAsync(player.Userid)
end)
if success then
Folder = data
else
print("Data Error")
warn(errormessge)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId)
end)
if success then
print("Data fully saved")
else
print("Data error")
warn(errormessage)
end
The last time I saved “items” in Data Stores I created a BoolValue for every item and then I would set it’s value to true if the item was bought and keep it false if it wasn’t bought.
Making a new datastore for each item is not a great idea, what you should do instead is pack all the items the player owns in a table/dictionary and store that instead. for example:
{
"Item1",
"Item2"
}
That way when you load a player’s data you won’t have to make a ton of requests to multiple datastores but instead, make 1 request to fetch all data which then you could use to iterate over and instance StringValues for each item/keep them in a table, up to you.