Save tools after leaving and loading them after not working

Why wont this work?

local script that clones tool (item giver)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ProximityPrompt = script.Parent:WaitForChild("ProximityPrompt")
local sound = workspace:WaitForChild("Sons"):WaitForChild("Agarrar")
local cartao = script.Parent
local toolevento = ReplicatedStorage:WaitForChild("ToolParaServer")

ProximityPrompt.Triggered:Connect(function(player)
	local Tool = game:GetService("ServerStorage"):WaitForChild("SavedTools2"):WaitForChild("Cartão"):Clone()

	sound:Play()
	Tool.Parent = player:WaitForChild("Backpack")
	wait(0.3)
	ProximityPrompt:Destroy()
	cartao:Destroy()
	toolevento:FireServer(player, Tool.Name) 
end)

data tool saver:

local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools2")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local ToolParaServer = ReplicatedStorage:FindFirstChild("ToolParaServer")

game.Players.PlayerAdded:Connect(function(Player)
	local ToolData = SaveData:GetAsync(Player.UserId)

	local Backpack = Player:WaitForChild("Backpack")
	local StarterGear = Player:WaitForChild("StarterGear")

	if ToolData ~= nil then
		for i, v in pairs(ToolData) do
			if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
				ToolFolder[v]:Clone().Parent = Backpack
				ToolFolder[v]:Clone().Parent = StarterGear
			end
		end
	end

	Player.CharacterRemoving:Connect(function(Character)
		Character:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local ToolTable = {}

	for i, v in pairs(Player.Backpack:GetChildren()) do
		table.insert(ToolTable, v.Name)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)

ToolParaServer.OnServerEvent:Connect(function(player, toolName)
	local Tool = ToolFolder:FindFirstChild(toolName)
	if Tool then
		local Backpack = player:FindFirstChild("Backpack")
		local StarterGear = player:FindFirstChild("StarterGear")
		if Backpack and StarterGear then
			Tool:Clone().Parent = Backpack
			Tool:Clone().Parent = StarterGear
		end
	end
end)

1 Like

Have you tried testing on an actual Roblox server and not on the Studio?