How do I make the max amount of items in your inventory 3!
How do I edit players inventory?
3 answers
Howdy!
I'd try a function that checks the inventory every few seconds. A table with three strings gets updated with the names of the items. If no room is there, the item is destroyed. The possibilities are endless. Someone else might have different ideas.
If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.
Be sure to check out the Roblox API Documentation as well for additional reference.
1 comment
heres the thing i just got started on scripting so i dont really know how to do this! can you give more info about what your saying please!
Well Sir, it is pretty simple. All you have to do to insert the item into the starter-pack and every player will have the item!!!!
No coding needed sir!!!!!!!!!!!!!!!!!!!!!!!!!!
1 comment
Yes, that would put items into the player's backpack, but it would not limit the maximum quantity of items in their backpack.
The way I would go about this would be to utilise the ChildAdded event of instances.
You can connect a function to this event and determine the amount of items currently in the backpack with the length of the table returned by :GetChildren() when called on the backpack.
From there, you would want to compare the length of that table to some constant defined within your script/game, and if it is greater than this constant, the inventory limit has been exceeded. I will leave an example below but am not going to give you a full implementation, you will learn more by doing this yourself! :)
local Players = game:GetService("Players")
local MAX_ITEMS = 3 -- This is the constant I discussed earlier
local player = Players.LocalPlayer
local backpack = player:FindFirstChild("Backpack")
backpack.ChildAdded:Connect(function(newChild)
local backpackChildren = backpack:GetChildren()
local backpackSize = #backpackChildren -- the hash (#) here indicates that we want the length of the array
if backpackSize > MAX_ITEMS then
... -- Your actions
end
end)
(I gave a bit more info there than I was planning to originally, but hopefully it's helpful)
A side note: In the future, please try to make an attempt at making what it is you want before you come here to ask as not only will you have a better chance at getting an answer, but it gives us more to work with. (see the community guidelines for more info)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
yes