local DataStoreService = game:GetService("DataStoreService")
local ToolsData = DataStoreService:GetDataStore("ToolsData")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local AllTools = ServerStorage.Tools
local CombatTagFolder = ServerStorage.CombatTaggedPeople
local GetCharacterFromPlayer = require(ReplicatedStorage.ModuleScripts.GetCharacterFromPlayer)
local temptools = {
ServerStorage.Tools.Food,
}
local function savetools (player)
local toolslist = {}
for i,tool in pairs(player.Backpack:GetChildren()) do
if temptools[1]:FindFirstChild(tool.Name) then
if tool:IsA("Tool") then
table.insert(toolslist,tool.Name)
end
end
end
local Success , Fail = pcall(function()
ToolsData:SetAsync(player.UserId, toolslist)
end)
if not Success then
warn(Fail)
ToolsData:SetAsync(player.UserId, toolslist)
end
end
local function loadtools (player)
local playerbackpack
local success,fail = pcall(function()
playerbackpack = ToolsData:GetAsync(player.UserId)
end)
if not success then
warn(fail)
playerbackpack = ToolsData:GetAsync(player.UserId)
end
print(playerbackpack)
if playerbackpack then
for i,tool in pairs(playerbackpack) do
print(tool)
if AllTools:FindFirstChild(tool) then
AllTools[tool]:Clone().Parent = player.Backpack
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
loadtools(player)
player.CharacterRemoving:Connect(function(character)
local tag = CombatTagFolder:FindFirstChild(player.Name)
if tag then
tag:Destroy()
character.Humanoid:UnequipTools()
for i,tool in pairs(player.Backpack:GetChildren()) do
if tool:IsA("Tool") and tool:FindFirstChild("Handle") then
tool.Parent = game.Workspace
tool.Handle.CFrame = character.HumanoidRootPart.CFrame + Vector3.new(0,20,0)
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
savetools(player)
end)
game:BindToClose(function()
if not RunService:IsStudio() then
for i,player in ipairs(game.Players:GetPlayers()) do
coroutine.wrap(savetools(player))
end
end
end)
ima go eat breakfast cant find da problem also no errors