Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to change the properties of a new instance?

Asked by 7 years ago

For example lest say that I add a Special Mesh into a brick using this code- and I set up a id for it to

local BananaID = 'http://www.roblox.com/asset/?id=1337'
Instance.new('SpecialMesh')

How do you add the BananaID into the mesh ?

3 answers

Log in to vote
1
Answered by 7 years ago

Hey there.

To act upon the properties of a new instance, you assign that new instance to a local variable. So let's say I was creating a new part, and I wanted to call it "brick". The code would look like this...


local brick = Instance.new ("Part")

This assigns the local variable brick to your new part. Now, you can change the properties of this part, by referencing its variable. So, let's say I wanted to change it's position to 0,0,0. The code would look like this:

local brick = Instance.new ("Part")
brick.Position = Vector3.new (0,0,0)

This principle can be used with any property, of any new instance you create, if you know how to use the property correctly.

Hope this helps. Good luck.

Ad
Log in to vote
2
Answered by 7 years ago

Store a variable to the instance first:

local mesh = Instance.new'SpecialMesh' --\\Create the mesh

Then set the meshType to FileMesh

mesh.MeshType = Enum.MeshType.FileMesh --\\Set the mesh type

Then set the meshId

mesh.MeshId = BananaID --\\Set the mesh's ID

Make sure you have already defined BananaID!

0
Could you put that all together for me? salmonbear242 50 — 7y
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Let me put it all together for you in one block of code. Here is the code and I will commentate along the way to explain what each line does.

Block Of Code:

local mesh = Instance.new("SpecialMesh"); -- A Variable set for the instance of Special Mesh.
local BananaID = "http://www.roblox.com/asset/?id=1337"; -- Variable for the ID that you defined in your code.
mesh.MeshType = "FileMesh";    -- Changes the Special Mesh's MeshType to FileMesh.
mesh.MeshId = BananaID;  -- Sets the MeshId property of the Special Mesh to the ID that the variable is defined as.

If you see the semi-colons do not worry about them Lua does not require them and I am trying to get used to putting them at the end of every line of my code since, most other programming languages use semi-colons.

Well, there ya go and I hope I made some sense of the code and sorry if my explaination is a bit out of wack. No one explained those to me in person I just had to get them self-taught.

Well, I hope I helped ya and if you have any questions please, comment down below.

Thanks,

~~ KingLoneCat

0
Using a string is bad practice, use enums. RemasteredBox 85 — 7y

Answer this question