Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Vector3 as an argument in function?

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?

1 comment

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.

1 answer

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))

2 comments

0

Thanks this helped a lot!

0

You're welcome. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.