Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Keeping gear after death?

im trying to make a script that makes it so that you keep a gear after you die but i have no clue how to do it, its meant for a egg hunt event in my own game where you collect eggs and have to get all of them to get a badge award, but when you die you have to get the eggs (they are gears) again.

1 comment

0

To properly keep items, store them within StarterGear whilst cloning to the Backpack.

1 answer

I remember how I struggled to make this script. I will be nice and give you mine so you don't have to go through everything I had to go trough, it works with R6 and R15. Place the script inside ServerScriptService Make it a ServerScript aka Script not LocalScript

function waitForSpawn(player)
	for i=1,100 do
		if player == nil then return false end
		if player.Character ~= nil and player.Character.Humanoid ~= nil and player.Character.Humanoid.Health ~= 0 then
			return true
		end
		wait(1)
	end
	return false 
end
function die(player, h)	
	    if h.Health == 0 then
		local items = {}
		local backpackItems = player.Backpack:getChildren()
		local charItems = player.Character:getChildren()	
		for i=1,#backpackItems do
		table.insert(items, backpackItems[i]:clone())
		end		
		for i=1,#charItems do
		if 	(charItems[i].className == "Tool") then
		table.insert(items, charItems[i]:clone())
		end
		end
waitForSpawn(player)
		if player ~= nil then		
		local backpackItems = player.Backpack:getChildren()
		for i=1,#backpackItems do
		backpackItems[i]:remove()
		end		
		local charItems = player.Backpack:getChildren()
		for i=1,#charItems do
			if 	(charItems[i].className == "Tool") then
		charItems[i]:remove()
		end
		end		
	for i=1,#items do
		items[i].Parent = player.Backpack
end
end
end
end
function aspawn(character)
	local h = character:findFirstChild("Humanoid")
	if h ~= nil then
		local player = game.Players:playerFromCharacter(character)
		if player ~= nil then
			h.Changed:connect(function () die(player, h) end)
		end
	end
end
game.Workspace.ChildAdded:connect(aspawn)

4 comments

0

thanks, man!

0

Every inch of this is wrong

0

14dark14 solution is work, but Feahren solution is better.

0

@Feahren - can you just accept others work? or do you need to be pretentious. I personally think this script is good. your might be a few lines longer than his script but i personally don't like the "I know it all," type of person. He's a beginner and off to a great start. Geez this platform is so toxic

This discussion is preserved as it was. New answers, comments, and votes are closed.