Just asking, Is it possible to spawn a brick or a part through a script, that will have inside a children a script ?
✓ ANSWER ACCEPTED
Is it possible to spawn a part with script inside of it ?
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.
Yes, use :Clone.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
yes