How do I make something like the roblox moneybag gear

The roblox moneybag gear creates multiple bucks at once I wanna know how to clone like that. Like clone more than one object at once.

You could run a loop for a set number of times, cloning the object you want to clone.

Create a new table with the money clones in it, then parent that to workspace with the random locations they would spawn at!

You would need to create a Tool and listen to it’s Activated event. The main logic of the Moneybag is that it’ll generate Money Parts and apply some offset into the Parts - Making all of them drop on a Random Position around the LocalPlayer’s HumanoidRootPart.

We can simply do this by just getting the HumanoidRootPart’s X, Y, Z positions and getting random values via Random.new():NextInteger() as offsets for so. Then we can apply all of that into a single CFrame, Create new Parts and apply the CFrame to each part. (Note that each CFrame will vary depending on the value generated)

For proper management and for the sake of optimization, We need to cache and keep all the parts we create into an array - Which we’re gonna clean later on to avoid keeping old parts inside the game and avoid lag.

Note that it’s highly recommended to make this on the Client-side, Since doing it on Server would cause even more lag. But that’s up to you. I’ve made a script for each side. (Server & Client)

Make sure that for the Server script, You use a Script and for the Client script a LocalScript (By the way, It must be inside the tool to make it work)

-- Server
local Players = game:GetService("Players")

local Tool = script:FindFirstAncestorOfClass("Tool")
local ToolMoneyParts = {}

local LocalPlayer = Tool:FindFirstAncestorOfClass("Player")
local LocalCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalRootPart = LocalCharacter.PrimaryPart or LocalCharacter:WaitForChild("HumanoidRootPart")

local RNG = Random.new()

local MONEY_PARTS_TO_GENERATE = 15
local MONEY_GENERATE_INTERVAL = 0
local MONEY_CLEANUP_DELAY = 5
local MONEY_DROP_COOLDOWN = false

--[[
	@ CreateMoneyPart
	Creates a new Money Part and adds it into the `ToolMoneyParts` array.
	This ensure all the Parts we create gets cached to later-on clean them up.
--]]

local function CreateMoneyPart(): BasePart
	local Part = Instance.new("Part")
	Part.Name = "ToolMoneyPart"
	Part.Color = Color3.fromRGB(55, 255, 55)
	Part.Size = Vector3.new(2, 0.25, 1)
	Part.Anchored = true
	Part.CanCollide = true
	Part.CanQuery = true
	Part.CanTouch = false
	Part.Material = Enum.Material.SmoothPlastic

	local TotalMoneyParts = table.getn(ToolMoneyParts)
	local NextMoneyPartSlot = TotalMoneyParts + 1
	table.insert(
		ToolMoneyParts, 
		NextMoneyPartSlot, 
		Part
	)

	return Part
end

--[[
	@ DestroyAllMoneyParts
	Destroys all the Money Parts inside `ToolMoneyParts` array.
	We MUST remove the previous Parts, Otherwise it would cause alot of lag if we just kept them.
--]]

local function DestroyAllMoneyParts()
	for _, Part in ipairs(ToolMoneyParts) do
		Part:Destroy()
	end
end

--[[
	@ ClearAllMoneyParts
	Similiar to `DestroyAllMoneyParts`, But it'll clear the array keys and replace the old `ToolMoneyParts` array with a new one.
--]]

local function ClearAllMoneyParts()
	table.clear(ToolMoneyParts)
	ToolMoneyParts = {}
end

--[[
	This is where we listen to whenever the Tool gets activated.
	All the logic for the tool is below here.
--]]

Tool.Activated:Connect(function()
	-- If we're on a cooldown, Stop.
	if MONEY_DROP_COOLDOWN then
		return
	end

	-- There's no RootPart? Stop!
	if not LocalRootPart then
		return
	end

	-- Set cooldown before we actually generate the Parts.
	MONEY_DROP_COOLDOWN = true

	-- Create the Money Parts.
	-- The amount of generated parts will be equals to `MONEY_PARTS_TO_GENERATE`.
	for X = 1, MONEY_PARTS_TO_GENERATE do
		-- Get the X, Y and Z RootPart positions.
		local RootX = LocalRootPart.Position.X
		local RootY = LocalRootPart.Position.Y
		local RootZ = LocalRootPart.Position.Z

		-- Generate extra offset for the X, Y and Z positions.
		local RandomX = RNG:NextInteger(-5, 5)
		local RandomY = RNG:NextInteger(1, 5)
		local RandomZ = RNG:NextInteger(-5, 5)

		-- Create a new CFrame for the Part.
		local NewPartCFrame = CFrame.new(
			RootX + RandomX, 
			RootY + RandomY, 
			RootZ + RandomZ
		)

		-- Now we create the Part, Set it's CFrame and parent it to workspace.
		-- Note that the `Part.CFrame:ToObjectSpace()` function will just make it;
		-- So the CFrame we pass into it will be equals to the Part's CFrame multiplied by the passed CFrame.
		local Part = CreateMoneyPart()
		Part.CFrame = Part.CFrame:ToObjectSpace(NewPartCFrame)
		Part.Anchored = false
		Part.Parent = workspace
		Part:SetNetworkOwner(nil)

		-- If `MONEY_GENERATE_INTERVAL` is bigger than 0, Await the time needed.
		if MONEY_GENERATE_INTERVAL > 0 then
			task.wait(MONEY_GENERATE_INTERVAL)
		else
			task.wait()
		end
	end

	-- Delay to clean-up the Parts and remove `MONEY_DROP_COOLDOWN`.
	-- Never forget to clean them up!
	task.delay(MONEY_CLEANUP_DELAY, function()
		DestroyAllMoneyParts()
		ClearAllMoneyParts()
		MONEY_DROP_COOLDOWN = false
	end)
end)

-- Client
local Players = game:GetService("Players")

local Tool = script:FindFirstAncestorOfClass("Tool")
local ToolMoneyParts = {}

local LocalPlayer = Players.LocalPlayer
local LocalCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalRootPart = LocalCharacter.PrimaryPart or LocalCharacter:WaitForChild("HumanoidRootPart")

local RNG = Random.new()

local MONEY_PARTS_TO_GENERATE = 15
local MONEY_GENERATE_INTERVAL = 0
local MONEY_CLEANUP_DELAY = 5
local MONEY_DROP_COOLDOWN = false

--[[
	@ CreateMoneyPart
	Creates a new Money Part and adds it into the `ToolMoneyParts` array.
	This ensure all the Parts we create gets cached to later-on clean them up.
--]]

local function CreateMoneyPart(): BasePart
	local Part = Instance.new("Part")
	Part.Name = "ToolMoneyPart"
	Part.Color = Color3.fromRGB(55, 255, 55)
	Part.Size = Vector3.new(2, 0.25, 1)
	Part.Anchored = true
	Part.CanCollide = true
	Part.CanQuery = true
	Part.CanTouch = false
	Part.Material = Enum.Material.SmoothPlastic

	local TotalMoneyParts = table.getn(ToolMoneyParts)
	local NextMoneyPartSlot = TotalMoneyParts + 1
	table.insert(
		ToolMoneyParts, 
		NextMoneyPartSlot, 
		Part
	)

	return Part
end

--[[
	@ DestroyAllMoneyParts
	Destroys all the Money Parts inside `ToolMoneyParts` array.
	We MUST remove the previous Parts, Otherwise it would cause alot of lag if we just kept them.
--]]

local function DestroyAllMoneyParts()
	for _, Part in ipairs(ToolMoneyParts) do
		Part:Destroy()
	end
end

--[[
	@ ClearAllMoneyParts
	Similiar to `DestroyAllMoneyParts`, But it'll clear the array keys and replace the old `ToolMoneyParts` array with a new one.
--]]

local function ClearAllMoneyParts()
	table.clear(ToolMoneyParts)
	ToolMoneyParts = {}
end

--[[
	This is where we listen to whenever the Tool gets activated.
	All the logic for the tool is below here.
--]]

Tool.Activated:Connect(function()
	-- If we're on a cooldown, Stop.
	if MONEY_DROP_COOLDOWN then
		return
	end

	-- There's no RootPart? Stop!
	if not LocalRootPart then
		return
	end

	-- Set cooldown before we actually generate the Parts.
	MONEY_DROP_COOLDOWN = true

	-- Create the Money Parts.
	-- The amount of generated parts will be equals to `MONEY_PARTS_TO_GENERATE`.
	for X = 1, MONEY_PARTS_TO_GENERATE do
		-- Get the X, Y and Z RootPart positions.
		local RootX = LocalRootPart.Position.X
		local RootY = LocalRootPart.Position.Y
		local RootZ = LocalRootPart.Position.Z

		-- Generate extra offset for the X, Y and Z positions.
		local RandomX = RNG:NextInteger(-5, 5)
		local RandomY = RNG:NextInteger(1, 5)
		local RandomZ = RNG:NextInteger(-5, 5)

		-- Create a new CFrame for the Part.
		local NewPartCFrame = CFrame.new(
			RootX + RandomX, 
			RootY + RandomY, 
			RootZ + RandomZ
		)

		-- Now we create the Part, Set it's CFrame and parent it to workspace.
		-- Note that the `Part.CFrame:ToObjectSpace()` function will just make it;
		-- So the CFrame we pass into it will be equals to the Part's CFrame multiplied by the passed CFrame.
		local Part = CreateMoneyPart()
		Part.CFrame = Part.CFrame:ToObjectSpace(NewPartCFrame)
		Part.Anchored = false
		Part.Parent = workspace

		-- If `MONEY_GENERATE_INTERVAL` is bigger than 0, Await the time needed.
		if MONEY_GENERATE_INTERVAL > 0 then
			task.wait(MONEY_GENERATE_INTERVAL)
		else
			task.wait()
		end
	end

	-- Delay to clean-up the Parts and remove `MONEY_DROP_COOLDOWN`.
	-- Never forget to clean them up!
	task.delay(MONEY_CLEANUP_DELAY, function()
		DestroyAllMoneyParts()
		ClearAllMoneyParts()
		MONEY_DROP_COOLDOWN = false
	end)
end)
1 Like