Hi,
Recently, I was trying to make an inventory system with categories and I was trying to make a table contains all items, effects, and trails that the player has but I got very confused while doing that.
What I tried to do:
local SSS = game:GetService("ServerScriptService")
local players = game:GetService("Players")
local giveDataEvent = SSS:WaitForChild("GiveDataStoreEvent")
dataStore2.Combine("Inventory", "Items", "Effect", "Trails")
players.PlayerAdded:Connect(function(plyr)
local itemsDataStore = dataStore2("Items", plyr)
local effectDataStore = dataStore2("Effect", plyr)
local trailsDataStore = dataStore2("Trails", plyr)
local inventoryFolder = Instance.new("Folder", plyr)
inventoryFolder.Name = "Inventory"
local itemsFolder = Instance.new("Folder", inventoryFolder)
itemsFolder.Name = "Items"
local effectFolder = Instance.new("Folder", inventoryFolder)
effectFolder.Name = "Effect"
local trailsFolder = Instance.new("Folder", inventoryFolder)
trailsFolder.Name = "Trails"
local function updataItemsData(itemsData)
itemsDataStore:GetTable(itemsFolder:GetChildren())
end
itemsDataStore:OnUpdate(updataItemsData)
end)
Although reading pretty much about this, I couldn’t do anything. (I haven’t skilled in that yet)
You cannot save Instances to a datastore.
You could try saving the names of the items and loading/saving using the item name instead of the instance.
1 Like
Alright, I know how can I do this. I made function that returns a table of names of items but I don’t know the how to save the table of the names or get the table (I tried :GetTable()).
If you have a table with names then you can save the table directly to a Datastore.
:GetTable() is a function of Datastore2 which is a module that isn’t maintained or owned by Roblox.
Just use Datastore:UpdateAsync() and return the list of items. Datastore:GetAsync() to retrieve them.
1 Like
I tried that but it gets an error:
Are you sure there is a function called :UpdateAsync()
because I looked in API list of DataStore2 and I didn’t find a function called that. I also tried to use SaveAsync()
but it gets the same error tells there is not :GetAsync()
function which made me more confused
I already told you, Datastore2 is not the official Roblox datastore. It is a user made module.
Look at the Roblox wiki for DataStoreService
Datastore2 is great if you know how it works, otherwise I would get a basic understanding of the Datastore service.
Datastore2 is great because it caches everything and auto-creates backups and has tons of support for serialization and such. If you really want to use Datastore2 I believe their method is :Set() (or :Increment() if it’s a number ) and you only need GetTable({}) on the first call to set default values.
1 Like