Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cant copy and paste a part with script and still work?

I have a part to make glass works fine until I copy it the old one is still fine but the copied one is not a glass window I figured later by changing the part name for each part which worked. but there should be a easier way to copy and paste it?

First Part

game.Workspace.GlassWindow1.Transparency = 0.7 game.Workspace.GlassWindow1.Material = ("Glass")

Second Part

game.Workspace.GlassWindow2.Transparency = 0.7 game.Workspace.GlassWindow2.Material = ("Glass")

New to coding lua any tips to would help a lot thank you.

1 answer

If you want to clone the window or any other object/instance use the :Clone() function!


--How to clone parts!

local GlassWindow1 = game.Workspace.GlassWindow1
GlassWindow1.Transparency = 0.7 
GlassWindow1.Material = ("Glass")

--If you want to clone this window use the :Clone() function!

local glasswindowClone = GlassWindow1:Clone()
--You can also clone it like this: game.Workspace.GlassWindow1:Clone()

--When you make a new clone it does not "spawn" inside the Workspace.
--You will need to put it inside the Workspace by Parenting it to the Workspace.

glasswindowClone.Parent = workspace

--Boom! You have a copy of the window!
--If you want to continuously spawn/clone them you can use a loop.

--I am assuming you do not know how a loop works yet, and I do not want this to become too confusing!
--If you would like to learn more about scripting I would recommend watching Alvin Blox's 2019 - 2020 Beginner Scripting Series on Youtube!

while true do
	
	local glasswindowClone = GlassWindow1:Clone()
	
	--Before putting the window clone in the Workspace you can set its properties such as it name, transparency, etc.
	glasswindowClone.Name = "WindowClone"
	
	glasswindowClone.Parent = workspace
	
	--Waits 1/10th of a second before proceeding.
	wait(0.1)
end

2 comments

1

or you can just... press CONTROL+D on the desired part

0

Sure, but what if you want to clone it while the game is running? (Which I assume is what she was asking.)

This discussion is preserved as it was. New answers, comments, and votes are closed.