Could someone tell me why my script for datastores isn’t saving ?
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local DataStore = game:GetService("DataStoreService")
local InventoryTemplate = ServerStorage.InventoryTemplate
local AbilityStore = DataStore:GetDataStore("Abilities")
local function Load(player)
local Inventory = InventoryTemplate:Clone()
Inventory.Name = "Inventory"
Inventory.Parent = player
local PlayerId = player.UserId
local Success, Table = pcall(function()
AbilityStore:GetAsync(PlayerId)
end)
if Success then
print(Table)
if Table == nil then return end
local AbilitiesInInventory = Inventory.Abilities:GetChildren()
for AbilityName, AbilityValue in pairs(Table) do
for i, v in pairs(AbilitiesInInventory) do
if v.Name == AbilityName then
v.Value = AbilityValue
end
end
end
end
end
local function Save(player)
local PlayerId = player.UserId
local Inventory = player.Inventory
local AbilityList = {}
local Abilities = Inventory.Abilities:GetChildren()
for i, v in pairs(Abilities) do
AbilityList[v.Name] = v.value
end
local Success, Error = pcall(function()
AbilityStore:UpdateAsync(PlayerId, function(OldList)
print(AbilityList)
return AbilityList
end)
end)
if not Success then
print(Error)
end
end
Players.PlayerAdded:Connect(Load)
Players.PlayerRemoving:Connect(Save)