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

Is it possible to spawn a part with script inside of it ?

Just asking, Is it possible to spawn a brick or a part through a script, that will have inside a children a script ?

1 comment

0

yes

2 answers

✓ Accepted answer

Yes. In fact, this would be very simple. First you would spawn in a part.

local newpart = Instance.new("Part")
newpart.Parent = game.Workspace --This places the part into the workspace.

Then we would make a script and insert it into the part.

We can use Instance.new to spawn a script, just like we used it with the part.

local newscript = Instance.new("Script")
newscript.Parent = newpart --This places the script into the part.

Full script:

local newpart = Instance.new("Part")
newpart.Parent = game.Workspace
newpart.Name = "Test"
 
local newscript = Instance.new("Script")
newscript.Parent = newpart

Or if you don't want to spawn a new part, and instead a preexisting part, you could do this:

local partyouwanttoclone = game:GetService("ServerStorage"):WaitForChild("nameofyourpart") -- You can change this to wherever you store your part

local clonedpart = partyouwanttoclone:Clone()

clonedpart.Parent = game.Workspace 

local newscript = Instance.new("Script")
newscript.Parent = clonedpart --This places the script into the part.

You could even clone a preexisting script and place it into your preexisting part. This could be done like this:

local partyouwanttoclone = game:GetService("ServerStorage"):WaitForChild("nameofyourpart") -- You can change this to wherever you store your part and the name of it

local clonedpart = partyouwanttoclone:Clone()

clonedpart.Parent = game.Workspace 

local scriptyouwanttoclone = game:GetService("ServerStorage"):WaitForChild("nameofyourscript") -- You can change this to wherever you store your script and the name of it

local clonedscript = scriptyouwanttoclone:Clone()
clonedscript.Parent = clonedpart --This places the script into the part.

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