local Data = game:GetService("DataStoreService"):GetDataStore("FDLKFJLDSJ")
local Tools = game.ServerStorage.Tools

game.Players.PlayerAdded:Connect(function(player)
	local pd = Data:GetAsync("FDSKLFKSD"..player.userId)
	if pd then
		for i,v in pairs(pd) do
			if Tools[pd[i]] then
				Tools[pd[i]]:Clone().Parent = player:WaitForChild("StarterGear")
				Tools[pd[i]]:Clone().Parent = player:WaitForChild("Backpack")
			end
		end
	else
		Tools.ClassicSword:Clone().Parent = player:WaitForChild("StarterGear")
		Tools.ClassicSword:Clone().Parent = player:WaitForChild("Backpack")
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Tools = {}
	for i,v in pairs(player.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			table.insert(Tools,v.Name)
		end
	end
	for i,v in pairs(workspace[player.Name]:GetChildren()) do
		if v:IsA("Tool") then
			table.insert(Tools,v.Name)
		end
	end
	Data:SetAsync("FDSKLFKSD"..player.userId,Tools)
end)

Doesn't error?

1 comment

0

There may not be enough time for the data to save before the server closes after the last player leaves. You can try using this to wait longer before the server closes: http://wiki.roblox.com/index.php?title=API:Class/DataModel/BindToClose