New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# 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 ?

0
yes Edbotikx 96 — 9d

0

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.