So I created a data storage system that works pretty well for storing Revolver skins, for the past few months it has done a good job at keeping track of the players skins. But today I was adding an update to the game (Nothing in the datastore was changed) and I was only shown the default Revolver skin and not any of the others. I left the game and rejoined and all the skins were gone.
Is there a way to prevent this from happening again to other players?
Here is the code:
local ds = game:GetService("DataStoreService"):GetDataStore("HCSkinSaver")
game.ReplicatedStorage.LoadSavedData.OnServerEvent:Connect(function(plr)
local key = "id-"..plr.userId
pcall(function()
local skinfolder = Instance.new("Folder", plr)
skinfolder.Name = "skinfolder"
local skins = ds:GetAsync(key)
if skins then
for i,v in pairs(skins) do
local newval = Instance.new("BoolValue", skinfolder)
newval.Name = v
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function (plr) -- This was probably the line causing it to be deleted but without it skins also would not save.
local key = "id-"..plr.userId
local skinfolder = plr:WaitForChild("skinfolder")
pcall(function()
local skinsToSave = {}
if skinfolder ~= nil then
for i,v in pairs(skinfolder:GetChildren()) do
if v then
table.insert(skinsToSave,v.Name)
end
end
ds:SetAsync(key,skinsToSave)
end
end)
end)
game.Workspace.MainGame.TwitterStuff.RedeemCode.OnServerEvent:Connect(function(plr)
local key = "id-"..plr.userId
local skinfolder = plr:WaitForChild("skinfolder")
pcall(function()
local skinsToSave = {}
if skinfolder ~= nil then
for i,v in pairs(skinfolder:GetChildren()) do
if v then
table.insert(skinsToSave,v.Name)
end
end
ds:SetAsync(key,skinsToSave)
end
end)
end)
game.ReplicatedStorage.SellSkin.OnServerEvent:Connect(function(plr)
local key = "id-"..plr.userId
local skinfolder = plr:WaitForChild("skinfolder")
pcall(function()
local skinsToSave = {}
if skinfolder ~= nil then
for i,v in pairs(skinfolder:GetChildren()) do
if v then
table.insert(skinsToSave,v.Name)
end
end
ds:SetAsync(key,skinsToSave)
end
end)
end)
game.ReplicatedStorage.SkinWon.OnServerEvent:Connect(function(plr)
local key = "id-"..plr.userId
local skinfolder = plr:WaitForChild("skinfolder")
pcall(function()
local skinsToSave = {}
if skinfolder ~= nil then
for i,v in pairs(skinfolder:GetChildren()) do
if v then
table.insert(skinsToSave,v.Name)
end
end
ds:SetAsync(key,skinsToSave)
end
end)
end)
Here is a UI Visual:
Here is where skins are stored: