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