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

How do I allow people to have only a limited amount of inventory space?

Asked by 6 years ago

Also is there a way for me to add a little message when the player is trying to take to many items? For example when a player takes the 3rd item can there be a message saying "Inventory Full"?

1 answer

Log in to vote
0
Answered by
LuaDLL 253 Moderation Voter
6 years ago
Edited 6 years ago

What I would do:

Make a numbervalue and name it maxinventoryspace make a numbervalue and name it currentinventoryspace

local MaxInv = script.Parent.maxinventoryspace -- Or where ever you put the number value
local CurInv = script.Parent.currentinventoryspace -- where ever you put it
local InvFullText = script.Parent.InventoryFull -- The textlabel that says inventory full
local Inventory = script.Parent.Inventory -- Where the inventory is

function CheckInv()
    if CurInv.Value == MaxInv.Value then -- Checks If Player Can Have Item
        return false -- Returns false which will indicate you cannot have another item
    elseif CurInv.Value < MaxInv.Value then -- Checks If Player Can Have Item
        return true -- Returns true which will indicate you can have another item
    end
end

Inventory.ChildAdded:Connect(function(Child)
    if CheckInv() then -- If CheckInv returns true
        CurInv.Value = CurInv.Value + 1
        -- Do what you need to do here
    elseif not CheckInv() then -- If CheckInv returns false
        Child:Destroy()
        InvFullText.Visible = true
        wait(2)
        InvFullText.Visible = false
    end
end
Ad

Answer this question