How to save values inside a folder inside a Tool?

my game has a system to upgrade your weapons and buff them etc, but its been 3 days and i havent found a solution, so im asking here:

how to save values in a folder in a tool?

here’s my script, copied by a youtuber but is the only thing that worked for me

local ToolFolder = game:GetService("ReplicatedStorage"):FindFirstChild("Tools")
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)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)
1 Like

thanks yall for the help, but i managed to make this work with some dictionaries

2 Likes

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