Hey, so basically I made a character shop. The store is working perfectly but I am now struggling to save the bought skins.
Every skin in the game is added in form of a BoolValue to a folder inside a player, if the player has the skin, it will be true and if not, false. This is for the inventory handler to check which values are true and give those skins to the player
How can I save all the bool values in the player folder?
Here is my leaderstats code with only the parts for the skin thing and my attempt
local mySkins = Instance.new("Folder" , player)
mySkins.Name = "mySkins"
for i , v in pairs(game.ReplicatedStorage.Skins:GetChildren()) do -- Here is were the skins in the shop are located
skin = Instance.new("BoolValue" , mySkins)
skin.Name = v.Name
end
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)
if success then
if data then
skin.Value = data.skin
print("Data Loaded!")
end
else
print("There was an error while getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {
skin = player.mySkins:FindFirstChild(skin.Name).Value -- I am aware this is wrong
}
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId,data)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)
I know this is wrong because I am using the FindFirstChild and it is only taking 1st value and it is not working properly, but I tried using GetChildren() or GetDescendants() but couldn’t do it right.
Also not sure if I am overwriting the folder everytime the player joins with the for loop
Any help is really appreciated