im having a issue where tools wont save when they are equipped and the player leaves
save function
local function Save(player: Player)
local dataKey = 'key_' .. player.UserId
local data = PlayerData[player]
local success, result = pcall(function()
ItemStore:SetAsync(dataKey, data, {player.UserId})
end)
if not success then
error(result)
end
warn('Successfully saved', player, 'items to Datastore')
end
local function AddItem(item: Instance, folder: Folder, index: number)
if not data[folder.Name] then
data[folder.Name] = {}
end
if not index then
index = #data[folder.Name] + 1
table.insert(data[folder.Name], index, item.Name)
end
item.AncestryChanged:Connect(function(_, newParent)
if newParent ~= folder and folder.Parent ~= nil then
data[folder.Name][index] = nil
end
end)
end
for storeFolderName, savedItems in pairs(data) do
if onReset == true and storeFolderName ~= 'Backpack' then
continue
end
local itemsFolder: Folder = folders_to_save[storeFolderName]
if itemsFolder then
local folder = folders[storeFolderName]
for index, itemName in pairs(savedItems) do
local item = itemsFolder:FindFirstChild(itemName)
if item then
local playerItem = item:Clone()
playerItem.Parent = folder
AddItem(playerItem, folder, index)
else
warn(player, 'has unknown item that is said to be in folder', storeFolderName, ":", itemName)
end
end
else
warn(player, 'has unknown directory saved in data:', storeFolderName)
end
end
I have a working script that does this but I don’t think I should send it to anyone because it is vulnerable to save scumming which is basically where anyone on Roblox can abuse a vulnerability that allows them to revert to a previous data save if they don’t like what they received from RNG