I am making an update on my game adding sword skins and I decided to start with the hardest thing: saving the skins.
I decided to just save the tools in a folder inside the player, which did not work. I do not work much with datastore so the error might be very obvious.
There are no errors in the output and I based this script on a script for saving tools only I changed which folder it goes to and the names of some values inside of the script.
Here is the script:
local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("SwordSkins")
local skinsFolder = game.ReplicatedStorage.SwordSkins
game.Players.PlayerAdded:Connect(function(player)
local savedSkins = data:GetAsync(player.UserId.."SwordSkins")
if savedSkins then
for i, skin in ipairs(savedSkins) do
for i, tool in pairs(skinsFolder:GetChildren()) do
if skin == tool.Name then
local toolClone = tool:Clone()
toolClone.Parent = player.SwordSkins
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local suc, err = pcall(function()
local savedSkins = {}
for i, skin in pairs(player.SwordSkins:GetChildren()) do
table.insert(savedSkins, skin.Name)
end
data:SetAsync(player.UserId.."SwordSkins", savedSkins)
end)
end)
If you know what is wrong with my script, please let me know.