Ah I gtg, here is the code I had so far, you need to have a folder in replicatedStorage called "SaveableTools" with every tool you want to allow to be saved in it.
This goes in a regular script in workspace or ServerScriptService
local SaveTools = game:GetService("ReplicatedStorage")
local DataStore = game:GetService("DataStoreService"):GetDataStore("NameThisWhatYouWant") -- If you change it, all data will be erased
game.Players.PlayerAdded:connect(function(player)
local key = "user_" .. player.userId
if DataStore:GetAsync(key) then
for _, Tool in pairs (DataStore:GetAsync(key)) do
for _, SaveTool in pairs (SaveTools:GetChildren()) do
if Tool.Name == SaveTool.Name then
SaveTool:Clone().Parent = player:WaitForChild("Backpack")
end
end
end
else
DataStore:SetAsync(key, {})
end
end)
game.Players.PlayerRemoving:connect(function(player)
local toolsToSave = {}
local key = "user_" .. player.userId
for _, v in pairs (player.Backpack:GetChildren()) do
table.insert(toolsToSave, v.Name)
end
for _, t in pairs (player.Character:GetChildren()) do
if t:IsA "Tool" then
table.insert(toolsToSave, t.Name)
end
end
DataStore:SetAsync(key, toolsToSave)
end)
|