Search code examples
robloxinventory

Put an object in the inventory with Roblox Studio


When I put an object in the backpack, the Explorer window shows these objects, but the inventory displayed stays empty. My code :

local objets = game.ServerStorage.aRamasser
local nbMaxObjets = 10
wait(5)
objets.Parent = game.Workspace

for indice,unObjet in pairs(objets:GetChildren()) do
    local ClickDetector = unObjet:FindFirstChild("ClickDetector")
    ClickDetector.MouseClick :Connect(
        function (joueur)
            local inventaire = joueur:FindFirstChildOfClass("Backpack")
            if inventaire then
                local nbObjets = table.getn(inventaire:GetChildren())
                if nbObjets < nbMaxObjets then
                    (unObjet:Clone()).Parent = inventaire
                    unObjet.Transparency = 1
                    unObjet.CanCollide = false
                    wait(15)
                    unObjet.Transparency = 0
                    unObjet.CanCollide = true
                end
            end
        end     
    )
end

Explanation : The objects are in the directory ServerStorage. At the begining of the game, in the script above (in Workspace), this directory is moved into Workspace. The objects are visible. Then, if a click is detected on one object, this object is cloned and that clone is put in Backpack. It works, I see them in Explorer. But not in the inventory :


Solution

  • Your object needs to be inside a tool, tool can come in the inventory gui.

    local tool = Instance.new("Tool")
    tool.Parent = inventaire
    (unObjet:Clone()).Parent = tool