I am making a tool saving system and I already am able to save items when the player dies from other means, but i’m having trouble trying to save their inventory when they fall into the void.
-
What do you want to achieve? Be able to save the held tool of a roblox character when they fall into the void. Save is an it is still in their inventory when they respawn.
-
What is the issue? When players fall into the void, I am unable to save their held item, and when they respawn they don’t have it anymore
-
What solutions have you tried so far? A script like this (below) that saves the players backpack and character tools on death doesn’t work because when you fall into the void all children of the character are immediately destroyed. or as im aware
local Players = game:GetService("Players")
function OnPlayerAdded(Player)
local SavedTools = {}
local function OnCharacterAdded(Character)
for Index, Tool in pairs(SavedTools) do --Loads all the saved tools from the player's last death
Tool.Parent = Player.Backpack
end
SavedTools = {}
local function OnDied() --Copies all your tools when you die and saves them to a table attached to the player
for Index, Tool in pairs(Player.Backpack:GetChildren()) do
local CopiedTool = Tool:Clone()
table.insert(SavedTools, CopiedTool)
end
for Index, Tool in pairs(Player.Character:GetChildren()) do --Checks if theres a tool being currently used/equipped by the player
if Tool:IsA("Tool") then
local CopiedTool = Tool:Clone()
table.insert(SavedTools, CopiedTool)
end
end
end
Character.Humanoid.Died:Connect(OnDied)
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
for Index, Player in pairs(Players:GetChildren()) do --Redundency incase a player has joined before the event sets up
OnPlayerAdded(Player)
end
Players.PlayerAdded:Connect(OnPlayerAdded)