How do I make an item disappear after using it?

I am making an escape game and I want the items to disappear after you use them. I tried scripting it, but it does not seem to work. Once I use a key I need it to leave the players inv. Here is my script:

1 Like

What is an “item”? A part? [] [] []

It is a key. When I unlock a door with the key I want it to disappear.

Is the ‘key’ a model or a part (Prob a meshpart/union)?

image

image

I assume (from your script) you touch the key to pick it up?

script.Parent.Touched:Connect(function(obj)
    local h = obj.Parent:FindFirstChildWhichIsA("Humanoid")
    if h and h.Health ~= 0 then
    local player = game.Playerss:GetPlayerFromCharacter(obj.Parent)
    if player then
          script.Parent.Parent.Parent = player.Backpack
    end
end)

Click detector script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    script.Parent.Parent.Parent = player.Backpack
end)
1 Like

The script I provided was me trying to make it disappear after using it. The when touched script it:
image

The pick up script works. And the key functions just fine. I just want it to leave the players inv after use.

If you want the key to “leave” the player’s backpack, find the player, index the tool & use Destroy() or Remove() on it. You can also just set the parent back to workspace so another player could grab the key.

player.Backpack["Black Key"]:Remove()
player.Backpack["Black Key"]:Destroy()
-- Use this in the function which the key needs to dissapear
1 Like

Where would I place this script? Like how would I do that.

Could you show the script where the player ‘uses’ the tool?

Could you please be more specific?

image

This is for the door that you use the key on.

The last line in both of these events are

script.Parent:Destroy()

which destroys the part “handle”, but not the tool. You will have an empty tool within the player’s backpack. Try replacing it (that is, if the other code work) with

script.Parent.Parent:Destroy()

So if I put this in the door script that I just provided, it will also remove the key from the players backpack? Like this comment if yes so you don’t have to try and bypass the characters.

Yes, if I’m not mistaken. Replace script.Parent:Destroy() with script.Parent.Parent:Destroy() then test your game.

1 Like

It is still in my inventory. Did I do something wrong? let me try and record it.

robloxapp-20220311-1051549.wmv (2.4 MB)

The like was a yes.

Do you mind telling me where this script is located? I assume the key’s handle?

1 Like