Hello,
I'm aware that the Character of a Player Object is removed faster than the function joined to a Player.PlayerRemoving signal can call. I'm helping develop a Tool Persistence Script for someone here and I was wondering if there were any ways to work around or compensate for this issue from the perspective of a ServerScript?
local DataStoreService = game:GetService("DataStoreService")
local ToolData = DataStoreService:GetDataStore("ToolData")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local function SaveTools(Player)
if not (Player) then return end
local Backpack = Player:FindFirstChild("Backpack")
--// Cannot be called because the Character is missing
local Humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
if (Humanoid) then Humanoid:UnequipTools()
local ToolsToSave = {}
for _,Tool in pairs(Backpack:GetChildren()) do
if (Tool:IsA("Tool") and ServerStorage.Tools[Tool]) then
table.insert(ToolsToSave, Tool.Name)
end
end
if (#ToolsToSave < 1) then return end
ToolData:SetAsync(Player.UserId, ToolsToSave)
end
end
Players.PlayerRemoving:Connect(SaveTools)
