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: Instance.new() arguments

Previous Thread :: Next Thread 
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
28 Jul 2011 04:19 PM
When I instance a new brick with a piece of code I type something like this:

Instance.new("Part", game.Workspace)

Since you can state the parent of the newly created part with the second argument of the function, then I was wondering if you could set the properties of the part right from the function. I think I've seen it before, but I'm not quite sure if it's possible. If it is, then how? :o
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
28 Jul 2011 04:37 PM
Instance.new("Part", game.Workspace).Name = "Brick"

lol
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
28 Jul 2011 04:43 PM
You can't set the properties using additional arguments, but you can edit one property by just indexing the return value of Instance.new, as Spectrumw showed. Other than that, you can either make a function that lets you do this, or you can edit the properties manually.
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
28 Jul 2011 05:24 PM
Setting one property (in addition to parent) can be done like this in one line:

Instance.new("Hint",workspace).Text = "Hint"

However, that cannot be a variable, so setting two properties (other than parent) requires a minimum of three lines:

v = Instance.new("Hint",workspace)
v.Name = "Hint"
v.Text = "Hint"

Also, if you want to remove it, you can't set another property using the Debris method. This is why a ForceField is short and sweet:

game:GetService("Debris"):AddItem(Instance.new("ForceField",workspace.BunnyBoy26),5)
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
29 Jul 2011 06:57 AM
Oh. I thought there was a simple way. D:
Report Abuse
RATEXmegaGAMER is not online. RATEXmegaGAMER
Joined: 10 Dec 2010
Total Posts: 4046
29 Jul 2011 07:30 AM
Make your own function for each object XD

function AddIntValue(name, val, parent)
local v = Instance.new("IntValue", parent)
v.Name = name
v.Value = val
end

AddIntValue("ROBLOX", 1337, Workspace)
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
29 Jul 2011 07:33 AM
I think it would be easier to just make a variable of the new object and change it's properties from there. :P

local p = Instance.new("Part", game.Workspace)
p.BrickColor = BrickColor.new('Really red')
--etc
Report Abuse
RATEXmegaGAMER is not online. RATEXmegaGAMER
Joined: 10 Dec 2010
Total Posts: 4046
29 Jul 2011 07:36 AM
@Flurite I know :P
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