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

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

I know this :

function example()

end

But then do I use local or Arguments / parameters?

2 comments

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.

0

Yes functions. In fact I got a new thing below.

2 answers

✓ Accepted answer

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.

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

1 comment

0

this is exactly right!

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