Save Tools Script Not Working

My save tools script in sss isnt working, no errors, just not working. Any help is appreciated.

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

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)
		print(ToolTable)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)
1 Like

Are you sure there’s no errors? Clone{} is incorrect syntax, it’s Clone(). If that still doesn’t work I recommend adding error handling and checking.

1 Like

I’ll try that right now. Also, for error handling, what would you suggest?

The first opportunity for that I see here is a line to only add tools to the Backpack and Starter Gear if they’re not already there. such as like,

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

1 Like

Okay, and changing Clone() didn’t work. I wonder if I’m accessing the datastore incorrectly.

1 Like

That didn’t seem to work either, any other suggestions? I’m going to throw some print() in there as well to see what isn’t working.

Well, I found one of the errors. I was checking serverstorage, not ReplicatedStorage for my folder. However, I’m not sure if it will work. Not sure why that didn’t give any errors though…

1 Like

From what im seeing you are. Whatever the issue is, that isnt one of them.

1 Like

That was the issue this whole time, I was checking the wrong service. I’m so sorry for wasting your time :rofl:

1 Like

lol Its ok. I’m glad you were able to fix it. Keep coding!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.