This is my save script inside the serverscriptservice. It’s from a youtube tutorial.
local DatastoreService = game:GetService("DataStoreService")
local SaveTools = DatastoreService:GetDataStore("SaveTools")
local toolfolder = game:GetService("ServerStorage"):FindFirstChild("SpawnTools")
game.Players.PlayerAdded:Connect(function(playeradded)
local tooldata = SaveTools:GetAsync("Plrs_"..playeradded.UserId)
local backpack = playeradded:WaitForChild("Backpack")
if tooldata ~= nil then
for i, v in pairs(tooldata) do
if toolfolder:FindFirstChild(v) then
toolfolder[v]:Clone().Parent = backpack
end
end
end
playeradded.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(playerleft)
local tooltable = {}
for i, v in pairs(playerleft.Backpack:GetChildren()) do
table.insert(tooltable,v.Name)
end
if tooltable ~= nil then
SaveTools:SetAsync("Plrs_"..playerleft.UserId,tooltable)
end
end)
Mostly it works but sometimes none of the tools save and when the player joins back everything is gone.