Duplicate a local part from a storage as fast as possible

I want to create a test place where parts duplicate fast (1-10 times per second) and their physics are executed by my PC and not the server. The parts then pile up and can be pushed away using an explosion.

The problem is that I’m not as advanced in scripting so I need help with writing a script for the cloning system. It has to be both fast and only on the client side, but all my knowledge doesn’t seem to work… The solutions that I have tried are different. Scripting of the cloning system inside a Script and LocalScript, using Instance.new, using both Part with ClickDetector and Button Gui… nothing did the expected result (create a part fast and on client side in workspace)
. This is the code that I used for cloning:

local Glass = game.ReplicatedStorage.Glass
script.Parent.MouseClick:Connect(function()
	Glass:Clone().Parent = workspace
end)

There is nothing that is significantly faster than what you just described, as far as I’m aware. Just how fast do you need it to be?

1 Like
local Glass = game.ReplicatedStorage.Glass
script.Parent.MouseClick:Connect(function()
	while true do
        Glass:Clone()
        Glass.Parent = game.Workspace
        wait()  
    end
end)

This should do what you are wanting, if you want an code to stop it, just tell me.

1 Like

Doesn’t this normally crash the server?

Oh yeah,wait a sec

[30 charsss]

Isn’t that script going to time out because there is no wait in your loop?

Try putting multiple parts in the storage and do:

for i,v in pairs(game.ReplicatedStorage:GetChildren()) do
local clone = v:Clone()
clone.Parent = workspace
end

Well,thats true,but it would do instantly,which would mean in many parts being loaded at the same time,at the “same” speed.Dont need to correct me if i’am wrong.

You didn’t make a variable for the clone

local Glass = game.ReplicatedStorage.Glass
script.Parent.MouseClick:Connect(function()
	while true do
   >>>> Glass:Clone()        --local cloned = Glass:Clone()
        Glass.Parent = game.Workspace
        wait()  
    end
end)

Which indicates that it will get the original part

1 Like

I made this so you can turn it on and off like a water tap but it rains "Glass"

local Glass = game.ReplicatedStorage.Glass
local on = false

script.Parent.MouseClick:Connect(function()
   if on then
     on = false
   else
     local cloned = Glass:Clone()
     cloned.Parent = game.workspace
     on = true
end)

while on == true do
   local cloned = Glass:Clone()
   cloned.Parent = game.workspace
   wait()
end
3 Likes
local Glass = game.ReplicatedStorage.Glass

script.Parent.MouseClick:Connect(function()
        local AmountOfClones = 10 -- Change this to the amount of copies you want.

        for i = 1, AmountOfClones do
        Glass:Clone().Parent = workspace
        wait(0.001) -- Change this number to how many seconds you want it to wait between making each clone. Or delete this line if you don't want it to wait at all.
        end
end)

Hope this helps :smile:

2 Likes

Your script is almost what I wanted to happen, but for some reason it didn’t work. Then I edited it to this:

local Glass = game.ReplicatedStorage.Glass
local on = false
script.Parent.MouseClick:Connect(function()
	if on then on = false else
		on = true
		while on == true do
			wait(0.1)
			Glass:Clone().Parent = workspace
		end
	end
end)

Now it works and I need the last thing, making the part physics local instead of global. The reason why I want this is because the more global moving parts, the more internet sent and recieved. So I can have low internet flow and greater part physics with making this part flow local only.

If you want it to only happen locally, just make that script a local script.

Yes but LocalScripts can’t access ServerStorage or Replicated storage which makes my duplicating fail when I use a LocalScript

I’m fairly certain a local script can access replicated storage.

1 Like

Ok, I’ll try it to see what happens in both TextButton and ClickDetector

Let’s just say, local scripts can’t access server storage or replicated storage…
You could use another method;
Remove Events

Replicated Storage

LocalScripts can access ReplicatedStorage

1 Like

You can store your remove event in replicated storage and the call script for it in server script service for when ever it’s functioned by the local script.

local script > StarterGui/Other but in player scripts
Script(server) > ServerScriptService
Remote Event > ReplicatedStorage

local script makes a remote event

local RemoteEvent= ReplicatedStorage:WaitForChild("remoteEvent")
---Button example;
local button = script.Parent.button
button.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer("duplicatePart", BrickColor.Green())
end
-------

server script checks the remote event

local ReplicatedStorage= game:GetService("ReplicatedStorage")
local remoteEvent= ReplicatedStorage:WaitForChild("remoteEvent")
local glass = game.ReplicatedStorage:WaitForChild("Glass")

local function duplicatePart(player, color)
	local clonedGlass = glass:Clone()
	clonedGlass.BrickColor = color
	clonedGlass.Parent = game.Workspace
end
 
remoteEvent.OnServerEvent:Connect(duplicatePart)

I suggest using this method, if you want to create a gui button

1 Like

If you would like to make a part click event then you need a click detector inside the part along with a script

--Server Script inside the clickable part
local ClickDetector = script.Parent.ClickDetector
local Glass = game.ReplicatedStorage.Glass

ClickDetector.MouseClick:Connect(function()
	local clonedGlass = Glass:Clone()
	clonedGlass.Parent = game.Workspace
	print('successfully duplicated part')
end)

I hope this helps!

1 Like