Hello,
I’ve got a datastore script where I save the players wins, but it’s not working!
I think it’s not saving, I don’t know why. The objects get inserted but not saved / loaded.
Script:
game.Players.PlayerAdded:Connect(function(plr)
local skins = Instance.new("Folder",plr)
skins.Name = "Skins"
local equipedSkin = Instance.new("StringValue",plr)
equipedSkin.Name = "CurrentSkin"
equipedSkin.Value = game.ReplicatedStorage.Settings:WaitForChild('DefaultSkinName').Value
local skinsStore,equipSkinStore
pcall(function()
skinsStore = dStore:GetAsync(plr.UserId.."Skins")
equipSkinStore = dStore:GetAsync(plr.UserId.."EquippedSkin")
end)
if equipSkinStore ~= nil then
equipedSkin.Value = equipSkinStore
end
if skinsStore ~= nil then
for i,v in pairs(skinsStore) do
local newSkin = Instance.new("ObjectValue",skins)
newSkin.Name = v
rEvents.UpdateBackpack:FireClient(plr,newSkin.Name)
end
end
if skins:FindFirstChild(ReplicatedStorage.Settings.DefaultSkinName.Value) then
else
local newSkin = Instance.new("ObjectValue",skins)
newSkin.Name = ReplicatedStorage.Settings.DefaultSkinName.Value
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local skins = plr.Skins
local eSkin = plr.CurrentSkin
pcall(function()
dStore:SetAsync(plr.UserId.."EquippedSkin",eSkin.Value)
local skinsList = {}
for i,v in pairs(skins:GetChildren()) do
if ReplicatedStorage.Skins:FindFirstChild(v.Name) then
table.insert(skinsList,v.Name)
end
end
dStore:SetAsync(plr.UserId.."Skins",skinsList)
end)
end)
I get no errors! Thanks for help!