This is my first real experience with datastores, so I’m asking for a bit of help. The situation is this: I have a few folders inside the player, and inside of these folders are things like tools, quests, codex entries ect. How would I save these? (It’s not the values inside of the things per se, but the fact that they’re in said folders).
I’ve read up a bit on Datastores but I’ve only found ways of saving values rather than contents.
So in short: I’m trying to save contents of the folders, so that when a player loads their game, they have their items, codex entries and quests inside their folders.
Any help is greatly appreciated! If I’ve been too unclear, feel free to ask for more information. Thanks in advance!
if you have a folder for said instances, use a table and save it into a datastore with the instances names. After the player joins, clone the instances back into their folder with the datastore.
This is what the intitial ‘setup’ looks like. Could you elaborate a little more on how I would create these IDs? And how would I save things like the current quest objective?
Hello! Thanks for the reply. I’ve posted a picture in the comments section; should your method work when it comes to saving the current quest objective and whatnot? Should I use :GetChildren() for crreating the table? And if you’re ok with it, what would it look like in essence?
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("WeaponsData")
local toolsFolder = game.ServerStorage.ToolsFolder
game.Players.PlayerAdded:Connect(function(plr)
local savedTools = toolsDS:GetAsync(plr.UserId) or {}
for i, savedTool in pairs(savedTools) do
if toolsFolder:FindFirstChild(savedTool) then
toolsFolder[savedTool]:Clone().Parent = plr:WaitForChild("OwnedWeapons")
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local savedTools = {}
for i, savedTool in pairs(plr.OwnedWeapons:GetChildren()) do
table.insert(savedTools, savedTool.Name)
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId, savedTools)
end)
if errormsg then warn(errormsg) end
end)
Hello! My bad, when you said “contents”, I immediately referred to physical models in a folder. @sniper74will provided an efficient method with saving the names
Good morning! I’ve given the script a proper look, and it seems like it should work. However, how would I save data like the quest objective? (a value that constantly changes while in the player folder, and is therefore not something I can clone from the storage to the folder without the objective being lost).