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

How would I create a function that has 2 parts created?

Asked by 5 years ago

I know this :

function example()

end

But then do I use local or Arguments / parameters?

0
could you please explain a bit more i dont quite understand. do you want to create parts using the example function or do you want to pass two parts into example and do something to those parts. royaltoe 5144 — 5y
0
Yes functions. In fact I got a new thing below. SharkOwen_dev 69 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Functions are used to make your code a lot more organized and convenient. For example let's say you wanted to create two parts a bunch of times in your code, then a function that creates two parts when you call it is really helpful.

Parameters are used when you have a function that requires more information to run. For example, if you have a function that creates a certain amount of parts based on what you input, then you use parameters.

Example:

function CreateParts(numberOfParts) -- parameter is the number of parts to create
    for i=1,numberOfParts do -- for loop to create the number of blocks
        local part = Instance.new("Part", workspace) -- part instance in workspace
    end
end

CreateParts(7) -- This creates 7 parts
CreateParts(100) -- This creates 100 parts

From what I understand, you want a function that creates two parts. So you do not need parameters in your function. You only need to make two parts.

This would create the following:

function example() -- function to create two blocks
    local p1 = Instance.new("Part", workspace) -- creates one block
    local p2 = Instance.new("Part", workspace) -- creates another block
end

example() -- Creates two blocks
example() -- Also creates two blocks

I hope I explained the purpose of parameters well enough and was able to help out.

Ad
Log in to vote
0
Answered by 5 years ago

What I’m thing is Arugments and parameters. So I think the script would look like this :

function part(name,trans,anchor,collide)
      local part1 = Instance.new(“part”)
      part1.name = name
      part1.transperency = trans
      part1.Anchored = anchor
      part1.CanCollide = collide
end

part(hello,0,true,true)

I don’t know if that’s right or not. Please remind me if it is

0
this is exactly right! InfinityEngine 223 — 5y

Answer this question