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

Vector3 as an argument in function?

Asked by
Ryzox 220 Moderation Voter
9 years ago

eg -

function CreatePart(Name,Size)
    Part = Instance.new("Part",workspace)
    Part.Name = Name
    Part.Size = Vector3.new(Size)
end

Is this how it would work or am I going about it in the wrong way?

0
This is fine, except you should use a local variable (they're faster). Also I would probably just set Size directly to the Size argument then supply the Vector3 when i call the function. Perci1 4988 — 9y

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

You can either have 4 parameters, with 3 of them as the elements of the Vector3 value:

function CreatePart(Name, x, y, z)

With line 4 as:

Part.Size = Vector3.new(x, y, z)

OR

You can have 2 parameters, with one of them the whole Vector3 value itself:

This is what Perci1 means to "supply the Vector3 when [Perci1] call the function."

function CreatePart(Name, Vector3Value)

With line 4 as:

Part.Size = Vector3Value

Option 1

CreatePart(ExampleName, 1, 1, 1)

Option 2

CreatePart(ExampleName, Vector3.new(1, 1, 1))
0
Thanks this helped a lot! Ryzox 220 — 9y
0
You're welcome. :) Redbullusa 1580 — 9y
Ad

Answer this question