Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I clear all the inventory of a player, including the selected item?

Asked by 5 years ago

I'm developing a roblox game and I only want the player to hold one item at a time. Whenever I use this code it clears all the items currently deselected: player.Backpack:ClearAllChildren(). However, if the player is holding an item it won't clear that item! Anyone know a solution?

1
player.Character:FindFirstChildOfClass("tool"):Destroy() theking48989987 2147 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

The thing is, the item you are holding does not show up in the backpack, it shows up in your character, so you can use this to clear the tool they are holding.


local holdingtool = player.Character:FindFirstChildOfClass("Tool") holdingtool:Destroy()
Ad
Log in to vote
0
Answered by 5 years ago

This script, once in a part, when touched, deletes all tools from the backpack and that of the player has in hand.

local part = script.Parent
local debounce = false

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
        for i,v in pairs(char:GetChildren()) do
            if v.ClassName == "Tool" then
                v:Destroy()
            end
         end
        for i,v in pairs(player.Backpack:GetChildren()) do
            if v:IsA("Tool") then
                v:Destroy()
            debounce = true
          end
        end
      end
    end)
  end)
end)

Answer this question