How do you make a character retain tools on dying?

In short the script looks like this:

local function storeBackpack(client,inventory,inventory_folder)
	for _, name in ipairs(inventory or { }) do
		local tool = tools[name]
		tool:Clone().Parent = client.Backpack -- For the player to use
		tool:Clone().Parent = inventory_folder -- For saving and loading
	end
end

Players.PlayerAdded:Connect(function(client)
	if client:FindFirstChild('Character') ~= nil then
		storeBackpack(client,inventory,inventory_folder)
	end
	client.CharacterAdded:Connect(function()
		storeBackpack(client,inventory,inventory_folder)
	end)
end)

It should be simple logic however whenever I’m trying to re arrange this arguement I still get double, none or a random pick in the script. Is there any arrangement that would help?

if you want to keep tools when the player dies
clone the tool into startergear and the backpack, on death the item will spawn back into the backpack

local function storeBackpack(client,inventory,inventory_folder)
	for _, name in ipairs(inventory or { }) do
		local tool = tools[name]
		tool:Clone().Parent = client.Backpack -- For the player to use
		tool:Clone().Parent = client.StarterGear
		tool:Clone().Parent = inventory_folder -- For saving and loading
	end
end
4 Likes

humanoid.died:
grab all tools from backpack and character into array and parent to nil
plr:Getpropertychangedsignal(“Character”):Wait()
Move all tools to a player’s backpack

1 Like

Yarik dude you the goat you’ve helped me one 3 different topics lately :sob:

1 Like

i through i did only once lol
char limit
Also this method i made is a little hacky and not very safe unless you have instant respawning

It’s a bit complicated… this script is showing the basic concept. link At least one way of doing it.
Create a “list” (array) of tools they have and save it, then clone that list back when they respawn.

This is very clearly the easiest and bestway to do this in my position. Specifically because I had a save system for items, it made it less of a hastle. Thank you <3

For anyone else who has the same problem, but doesnt have a inventory system like mine. You can save and remove items from starter gear through different strategies.

1 Like

This is a multiplayer game, and the problems are out of the way for now :smiley:

1 Like

Oh, I was thinking after they left the game… you just wanted a respawn thing…

1 Like

No I have a tweaked code from here:

I have one… (Sorry I misunderstood your question)

Packback
--Packback ServerScript
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	local packback = Instance.new("Folder")
	packback.Name = "Packback"
	packback.Parent = player

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

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