generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Cloning more than once, and inserting into all of the Children of a model?

Previous Thread :: Next Thread 
Programmer101 is not online. Programmer101
Joined: 27 Jul 2009
Total Posts: 1043
20 Mar 2012 06:43 AM
My first question is if I can clone more than once? Is this possible without a bunch of :Clone() lines?

My second is if I can actually insert those clones, (Or any object) into every object in a model. I was thinking this is how virus spreads work, but it has been a while since I've seen one.
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
20 Mar 2012 06:47 AM
You could write out a bunch of lines cloning an object, but it would be much more efficient so simply use a numeric for loop.

    for integer = 1, 10 do -- Alter.
        -- Code.
    end

{ Scripting level - intermediate. }
Report Abuse
Programmer101 is not online. Programmer101
Joined: 27 Jul 2009
Total Posts: 1043
20 Mar 2012 06:52 AM
So, like...

For integer = 1,10 do
integer = e:Clone() -- Assuming e exists
end

Like that?

What about the second question?
Report Abuse
vexStudio is not online. vexStudio
Joined: 18 Mar 2012
Total Posts: 55
20 Mar 2012 06:56 AM
    for integer = 1, 10 do
        local clone = e:Clone() -- Assuming 'e' exists.
        clone.Parent = "something" -- Alter the parent.
    end

As for your second question, yes, it is possible, but you would need to create a function that gets everything (children and descendants) of a service.

{ Scripting level - intermediate. }
Report Abuse
Programmer101 is not online. Programmer101
Joined: 27 Jul 2009
Total Posts: 1043
20 Mar 2012 07:01 AM
Thanks! I love you guys :)
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
20 Mar 2012 08:58 AM
Cloning and parenting to each child of a model.

Let's assume that this model is a model named 'Chl' in Workspace.

e = --[[ path here, remove notations. ]]
for _,v in pairs(Workspace.Chl:children()) do
if v:IsA("BasePart") then --Checks to see if current object in the model is a part, wedge, seat, or other variation.
e:Clone().Parent = v
end
end
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
20 Mar 2012 09:02 AM
And of course, I didn't think of multiple models.

e = --[[ path here ]]

function clto(clne,mod)
for _,v in pairs(mod:Clone()) do
if v:IsA("Model") then
clto(clne,v)
elseif v:IsA("BasePart") then
clne:Clone().Parent = v
end
end
end


Then we just need to call the function. Assuming 'e' is the object you want to clone, and let's say that Model 'asd' in Workspace is the model you'd like to clone the object to...And let's say that you want the object to be cloned into every Part, Wedge, etcetera, but not Script, Fire, Sparkles, etcetera, then..

clto(e,Workspace.asd)
Report Abuse
wargarkaztestplace is not online. wargarkaztestplace
Joined: 05 Oct 2009
Total Posts: 2852
20 Mar 2012 09:10 AM
@Grimm considering the guy ask for this kind of help , dont you think it would be a bit More Friendly to make that Script Less Compact?
Like easier to read..
Unfair for him


(unless you figured out what it mean )
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
20 Mar 2012 01:49 PM
I suppose I could explain it.. o:

e = --[[ path here ]]

function clto(clne,mod)
for _,v in pairs(mod:Clone()) do
if v:IsA("Model") then
clto(clne,v)
elseif v:IsA("BasePart") then
clne:Clone().Parent = v
end
end
end


'e' is a variable. It will serve as the object you would like to clone.

A function can be called using its name and the arguments to match its parameters. (What is inside the parenthesis)

What this does is loop through the second argument, which will be called variable 'mod'.
'v' is the item in the model we're currently at.
'_' is the index we're at. We won't be using it, however.

If the item we're on is a Model (:IsA() is a method that checks if the item is what is the argument. You can use ClassNames or, like I did, BasePart, which is a grouping of different ClassNames.), then we will call the same function with the model inside the original as the model we will search.
If it is not a model, and it is a BasePart (has the ClassName property as a Part, CornerWedgePart, FormFactorPart, ParallelRampPart, PrismPart, PyramidPart, RightAngleRampPart, SkateboardPlatform, SpawnLocation, TrussPart, VehicleSeat, or Seat [I think that's all of them..?]), then we will clone 'e' and place it inside of the object we were on, in the loop.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image