How would i save a ObjectValue when the player leaves?

You can write your topic however you want, but you need to answer these questions:

  1. i want to make it so a ObjectValue saves when the player leaves, parented inside the player so i can save their swords

  2. i have 0 experience with datastore

  3. i tried looking at other pages of the dev forum but it didnt work

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

If you don’t have any experience with data storage, it would be better to learn the fundamentals of data storage.

Here are some video links and forums to help you out.

1st of, i recomend you using an array to save the swords (im gonna try to explain later on)

local DataStoreService = game:GetService("DataStoreService") --you get the datastore service
local SwordsDatastore = DataStoreService:GetDataStore("Swords") --You define the datastore here

local DefaultWeapon = script.Parent:FindFirstChild("DefaultSword") --saves and loads the default sword

local function SaveData(Player)

	local Weapons = {} --thats the array/table where you can save the swords in

	for i,v in pairs(Player.Weapons:GetChildren() --this function loops through all the folder, you nee to change the name/location if im wrong
		if i:isA("ObjectValue") then
		table.insert(i, Weapons)
		SwordsDatastore:SetAsync(Player.UserId, Weapons)

local function PlayerAdded(Player)
	local SavedSwords
	local success, error = pcall(function()
		SavedSwords = SwordsDatastore:GetAsync(Player.UserId) --:GetAsync Loads the data from the datastore
	if not success then warn(error) end --warns if something went wrong

	local Folder ="Folder") --creates a new folder, where you can later insert the saved data
	Folder.Name = "Weapons"
	Folder.Parent = Player
-- the code for that comes here

	if not SavedSwords then --creates default data, you can add a default swords in that for example
		SavedSwords = {DefaultWeapon}
	Player.Stats.Level.Value = SavedSwords[1]

local function PlayerRemoving(Player)

for _, Player in ipairs(game.Players:GetPlayers()) do



thats interesting! i found an alternate way to do it tho but ty!

thank you, ill watch these later