Could anyone please point me in the right direction for saving my player's data?

Hey there,

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!

1 Like

You can assign each of the contents along with their respective values as an ID, and you can decode the string upon joining the game :slight_smile:

If you need additional information, feel free to ask :slight_smile:

2 Likes

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.

2 Likes

Hey there! Thanks for the reply.

ScreenDev

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?

1 Like

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?

1 Like

this is what it would somewhat look like.

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)
1 Like

Thanks! That should work with my scripted stuff aswell, cheers!

I’m gonna try that out later this evening or tomorrow, if it doesn’t work, I’ll leave another message in this thread. Thanks alot for the help!

To anyone stumbling upon this message; feel free to suggest more methods. Any help is appreciated!

1 Like

Something useful when making datastores is this plugin; DataStore Editor - Roblox

2 Likes

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 :slight_smile:

3 Likes

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).

1 Like