Keep item after death

I want to make a tool stay in the player’s backpack after death, and the item is given when that player clicks on a model of that tool, for it to be added to their backpack from ServerStorage.

The issue is that if a player dies, it disappears from their inventory, and you can’t click it again to get it back since an error comes, saying that the parent is locked, though the locked parent is backpack.

I searched for solutions on the web and the devforum, but I couldn’t find any for my exact problem.

Current script:

local serverStorage = game.ServerStorage
local storedKeycard = serverStorage.Keycard
local keycard = storedKeycard:Clone()

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if keycard.Parent ~= player.Backpack then
        keycard.Parent = player.Backpack
    end
end)

Just saying, I am not an experienced scripter so I have no idea on how to do this.

Thank you anyways. :slightly_smiling_face:

2 Likes

Maybe save their backpack in a table whenever a tool was deleted/added into the backpack.

1 Like

that’s the purpose of StarterGear for your code add this keycard.Parent = player.StarterGear

2 Likes

I tried it, now you can’t even get the keycard at all. I’m pretty sure it has to be Backpack, but I really don’t know.

1 Like

Nevermind. I just found the solution on the dev forum.

I used this script and it worked fine…

1 Like