Need help saving players tools on death

I need a way to save the players tools on death, then give it back to them when they respawn

I simply cannot figure it out, I perfer to not use data stores, as this is a single-player game and I feel that would be unnecessary

i have tried, cloning players backpack to a folder in Replicated Storage, aswell as moving tools to that folder, then moving it back into the players backpack
looking for posts on the forum, i mostly just found things using data stores.

the script is a local script, in starterGUI

the script:

hum.Died:Connect(function()
	viewmodel.Parent = game.ReplicatedStorage
	player.CameraMode = Enum.CameraMode.Classic
	hum:UnequipTools()
	player.Backpack:ClearAllChildren()
end)

2 Likes

Its called Player.StarterGear. (i know this isn’t perfect, but its probably fine for your usecase)

2 Likes

when a humanoid dies, you can make a check on the server begin and save all the tools equipped by doing

hum:UnequipTools()
local tools = player.Backpack:GetChildren()
player.Backpack:ClearAllChildren()

now you can then loop through the copy once the new character is added, you could do this by establishing a characteradded.Once event.

hum:UnequipTools()
local tools = player.Backpack:GetChildren()
player.Backpack:ClearAllChildren()
player.CharacterAdded.Once:Connect(function()
     for _,tool in tools do
         local clone = tool:Clone()
         clone.Parent = player.Backpack
     end
end)
2 Likes

thanks, it works, but i noticed it does not copy any children, just the tool itself, empty
can you teach me how to deal with this?

Just because you need to store data it doesn’t mean you need to store it forever, or so other servers can access it. You can store the current player tools as data in-game, so they only save in that server during player reset. You can do this by implementing your own tool system on top of the Roblox tool system, that has a list of players and their current tools. On reset it simply gives them those tools back.

1 Like

Along the same concept..

-- ServerScript in ServerScriptService
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local inventory = Instance.new("Folder")
	inventory.Name = "Inventory"
	inventory.Parent = player

	player.CharacterAdded:Connect(function(character)
		for _, tool in pairs(inventory:GetChildren()) do
			tool:Clone().Parent = player.Backpack
		end	inventory:ClearAllChildren()

		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function() humanoid:UnequipTools()
			for _, tool in pairs(player.Backpack:GetChildren()) do
				if tool:IsA("Tool") then
					tool:Clone().Parent = inventory
				end
			end
		end)
	end)
end)
1 Like

Thanks, it worked to my liking after a few tweaks

1 Like

I made that for the same reason you were talking about. More of a studio test for me without using the datastore constantly while building the rest of the program. I was even shocked it works so well.

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