Help to save skins for weapon

I want to save the purchased sword skins.
When buying a player, a part with the name of the skin is added to a special folder called “korzina” located in the player, if such a name is already present in the folder, then the skin can be equipped for free. Actually, I need to save the contents of korzina to save all the skins I bought.

I have already made a small script that should create a folder with the player’s name and items in it, and also, in theory, should somehow save their names in a table that I do not know where.

Something is not working, and I can’t figure out what. I’ve already read the save manuals, but I still don’t understand it very well.

Please help me or tell me what I need to do to save the skins.

here is the button local script

script.Parent.Activated:Connect(function()
	local player = game:GetService("Players").LocalPlayer

	if player.leaderstats.Coins.Value >= 250 and player.korzina:FindFirstChild("Gold") == nil then
		game.ReplicatedStorage.ChangeSkin:FireServer("rbxassetid://129239835607605")
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 250

		local skin = Instance.new("Part", player.korzina)
		skin.Name = "Gold"
	else player.korzina:FindFirstChild("Gold")
		game.ReplicatedStorage.ChangeSkin:FireServer("rbxassetid://129239835607605")
	end

end)

here is the script triggered by the event

game.ReplicatedStorage.ChangeSkin.OnServerEvent:Connect(function(player, skinID)
	local sword = player.Backpack:FindFirstChild("Sword") or player.Character:FindFirstChild("Sword")
	sword.Handle.Mesh.TextureId = skinID

end)

this is a script in ServerScriptService

ocal Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")

local player_data = DataStoreService:GetDataStore("player_data")

local skins = ServerStorage.Skins
local bskins = ServerStorage.BuyedSkins
-- skins - tools and bskins - inventories

Players.PlayerAdded:Connect(function(client)
	local key = "client_" .. client.UserId
	local inventory = player_data:GetAsync(key)
	
	local inventory_folder = Instance.new("Folder")
	inventory_folder.Name = client.Name
	inventory_folder.Parent = bskins
	
	for _, name in ipairs(bskins or { }) do
		local skin = skins[name]
		skin:Clone().Parent = client.korzina
		skin:Clone().Parent = inventory_folder
	end
end)

Players.PlayerRemoving:Connect(function(client)
	local key = "client_" .. client.UserId
	local skins = { }
	local inventory_folder = bskins[client.Name]
	
	for _, item in ipairs(inventory_folder:GetChildren()) do
		table.insert(skins, item.Name)
	end
	
	player_data:UpdateAsync(key, function(prev)
		return skins
	end)
	
	inventory_folder:Destroy()
end)

image

image

Thank you in advance

What’s the exact issue you’re having with the system? Is the korzina folder just not saving and loading when players join the game, or is there an issue with the skin system directly?

I’m sorry about the confusion, I’m just trying to make sure I understand what the problem is.

Oh, sorry, I got so carried away with the description of the process that I forgot to specify exactly what the problem is. It seems to me that the contents of the folder are simply not saved, I can not understand exactly, but it is certain that when you log into the game, the korzina folder is empty and you have to buy skins again. Nothing is saved in the future either.

According to the last script, some folder with the player’s name should appear, but I can’t check its presence because when I run the test, I don’t see the contents of the ServerStorage. I think I need to replace this folder with korzina or something else, but korzina is just like an improvised Backpack, but only to check for skins.

Yes you should do it with korzina. You could try and use custom attributes on each of the Skins to like flag which of them are skins and which are not and only save the ones that are skins.