You can use ModuleScript
for this, so you can reuse it in any Script
.
Create ModuleScript
and name it “BagSystem”, once your done with that, put this code; make sure to put it in the ReplicatedStorage
.
local module = {} -- Create a table
function module:pickup(player, bag) -- Create a new function that requires both player and bag object
for _, item in pairs(bag.Storage:GetChildren()) do -- Get all the ObjectValue children
(item.Value):Clone().Parent = player.Backpack -- Clone value to the player's backpack
end
bag:Destroy() -- Destroy the bag, since we picked it up
end
function module:drop(position, items) -- Create a new function that requires position which is vector3 and items which is a table
local bag = script.Bag:Clone() -- Clone the bag
local storage = Instance.new("Folder") -- Create a new folder, this is where we gonna store the item that suppose to be in the bag
storage.Name = "Storage" -- Rename it to "Storage"
storage.Parent = bag -- Put the folder in the bag
for _, item in pairs(items) do -- Get all the items from the table
local obj = Instance.new("ObjectValue") -- Create a new object value, this is where we gonna store the location of each item
obj.Value = item -- Set the value of the object value to the item
obj.Parent = storage -- Put the object value in the storage folder
end
local input = Instance.new("ProximityPrompt") -- Create new ProximityPrompt
input.ActionText = "Pickup" -- Set the action text to "Pickup"
input.ObjectText = "Bag" -- Set the object text to "Bag"
input.HoldDuration = 1 -- Set the hold duration; for this example it's set to 1
input.MaxActivationDistance = 8 -- Set the max activation distance; for this example it's set to 8
input.Triggered:Connect(function(player) -- Once the ProximityPrompt is triggered
input.Enabled = false -- Prevent players from using it again
self:pickup(player, bag) -- Call the pickup function that is located in this module
end)
input.Parent = bag -- Put ProximityPrompt in the bag
bag.Position = position -- Set the position of the bag to vector3 that some script has passed to us
bag.Parent = workspace -- Put the bag in the workspace
end
return module -- Return the module so we can require it
Be aware that we gonna use ProximityPrompt
for this, instead of ClickDetector
, as it’s more suitable for this purpose.
Now you got the module, create a Script
and name it whatever you want; place it in the ServerScriptService
and put this code.
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Get ReplicatedStorage through GetService()
local BagSystem = require(ReplicatedStorage.BagSystem) -- Require our module, so we can use it
BagSystem:drop(Vector3.new(5, 5, 5), {ReplicatedStorage.Items.MoneyStack}) -- Call drop function so we spawn a bag with items and in the specified by us location
Now once you are done with that, create a Folder
called “Items” and place it in the ReplicatedStorage
; make sure to put all the Tools
that you want to be dropped and picked up in there; also make sure to put the bag MeshPart
under the BagSystem
module and also don’t forget to unanchor it and make it collidable, otherwise; everything should look like this.

The final result should look like this.
So this is how you create a bag system. I hope you learned something today, and if you have any questions or concerns feel free to do, otherwise; happy coding

.
If you can’t get it work, here is the fully working example that I made: BagSystemExample.rbxl (49.3 KB) .