Saving held tool when player falls into the void

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.

  1. 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.

  2. 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

  3. 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)
1 Like

The tool will be in their character model within workspace while its equipped, so you will need to account for that in your script. Might want to look into DataStores to make it easier.

wait, how so using datastores?
i have a datastore code that saves the characters held item and backpack

You can place all tools you want the player to respawn with in the StarterGear class under the Player instance (in game.Players). This respawns all tools for the specific player.

yes, but the player doesn’t unlock these tools until later in the game, and I don’t want to give them the tools immediately. Would it work if i just put in there startertools after they unlock it and put it back there when they rejoin?

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