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)
Thank you in advance