local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("SaveToolScript")
game.Players.PlayerAdded:Connect(function(plr)
pcall(function()
local tool = DataStore:GetAsync("User-"..plr.UserId)
if tool then
for i,v in pairs(tool) do
local ToolFound = game.ReplicatedStorage.BuyToolItems:FindFirstChild(v)
if ToolFound then
ToolFound:Clone().Parent = plr.Backpack
ToolFound:Clone().Parent = plr.StarterGear
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
pcall(function()
local toolsave = {}
for i, tool in pairs(plr.Backpack:GetChildren()) do
if tool then
table.insert(toolsave, tool.Name)
end
end
DataStore:SetAsync("User-"..plr.UserId, toolsave)
end)
end)
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("SaveToolScript")
game.Players.PlayerAdded:Connect(function(plr)
local tool = DataStore:GetAsync("User-"..plr.UserId)
if tool then
for i,v in pairs(tool) do
local ToolFound = game.ReplicatedStorage.BuyToolItems:FindFirstChild(v)
if ToolFound then
ToolFound:Clone().Parent = plr.Backpack
ToolFound:Clone().Parent = plr.StarterGear
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local toolsave = {}
for i, tool in pairs(plr.Backpack:GetChildren()) do
if tool then
table.insert(toolsave, tool.Name)
end
end
DataStore:SetAsync("User-"..plr.UserId, toolsave)
end)
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("SaveToolScript")
local players = game:GetService("Players")
local storage = game:GetService("ReplicatedStorage")
local buyToolItems = storage:WaitForChild("BuyToolItems")
players.PlayerAdded:Connect(function(plr)
local res = DataStore:GetAsync("User-"..plr.UserId)
if res then
for i,v in pairs(res) do
local storageTool = buyToolItems:FindFirstChild(v)
if storageTool then
local toolBackpack = storageTool:Clone()
toolBackpack.Parent = plr:WaitForChild("Backpack")
local toolStarter = storageTool:Clone()
toolStarter.Parent = plr:WaitForChild("StarterGear")
end
end
end
end)
players.PlayerRemoving:Connect(function(plr)
local backpackTools = {}
local backpack = plr:WaitForChild("Backpack")
for i, tool in pairs(backpack:GetChildren()) do
if tool then
table.insert(backpackTools, tool.Name)
end
end
DataStore:SetAsync("User-"..plr.UserId, backpackTools)
end)
game:BindToClose(function()
local playerList = players:GetPlayers()
for i, plr in pairs(players) do
local backpackTools = {}
local backpack = plr:WaitForChild("Backpack")
for i, tool in pairs(backpack:GetChildren()) do
if tool then
table.insert(backpackTools, tool.Name)
end
end
DataStore:SetAsync("User-"..plr.UserId, backpackTools)
end
end)