hello developers! i have this tool saving system taken from a youtube video and it does work. the problem is that the tool does not save when you reset but it saves when you rejoin having tool being held/in the backpack. i’ve tried taking the tooldata part in the player added function into the character removing function but it didn’t work. i’ve also searched for issues for this bug and found this. i have tried to use the solution and changed the code for it to make it properly work, but it didn’t work. any help appreciated!
(this is my first post so i’m expecting it to be bad)
local toolFolder = game:GetService("ServerStorage"):FindFirstChild("tools"):FindFirstChild("shop")
local dataStoreService = game:GetService("DataStoreService")
local saveData = dataStoreService:GetDataStore("SaveData")
game:GetService("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:GetService("Players").PlayerRemoving:Connect(function(player)
local toolTable
for i, v in pairs(player.Backpack:GetChildren()) do
if not toolTable then
toolTable = {}
end
table.insert(toolTable, v.Name)
end
if toolTable then
saveData:SetAsync(player.UserId, toolTable)
end
end)