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

Is it possible to max inventory slots in game?

Asked by 3 years ago

I am thinking of creating a system where players can hold up to 3 items at once in a game, here is my code so far.

local MAX_ITEMS = 3

game.Players.PlayerAdded:Connect(function(player)
    local Tools = Instance.new("IntValue",player)
    Tools.Name = "Tools"
    local backpack = player:WaitForChild("Backpack")
    backpack.ChildAdded:Connect(function(item)
        if item:IsA("Tool") then
            if Tools.Value > MAX_ITEMS then
                --Needing Help Here
                print("Too Many Items")
            else
                Tools.Value += 1
                print("ToolAdded")
            end
        end
    end)
    backpack.ChildRemoved:Connect(function(itemR)
        if itemR:IsA("Tool") then
            Tools.Value -= 1
            print("ToolRemoved")
        end
    end)
end)

Here, I need a way to not add the tool to the players backpack, but also not to mess up the Tools value, or to destroy the tool after being picked up. Anyone help?

Answer this question