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"?
✓ ANSWER ACCEPTED
How do I allow people to have only a limited amount of inventory space?
1 answer
✓ Accepted answer
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
