What am I doing wrong?

I’m currently learning about parameters & arguments in a function, could anybody direct me on what I did wrong while the parts are not spawning in while I run the game.

image

1 Like

To help us help you, it’s also important to provide your code as text as opposed to a screenshot. Additionally, output messages or errors that the code generates in the Output window could tell what’s happening.

2 Likes

I haven’t received any errors in the output messages for some weird reason, the parts won’t just spawn in, could it possibly be the reason that the script was misplaced?

Where is the script? Can you show us the explorer?

I’ve located it and I did accidently place it in “Server Storage” and not “ServerScriptService”

The brick is completely spawning in now, but the properties are not applying, and a second brick is not being placed into the map.

This is the current output image

Change your function to this:

local function Generatepart(name, IsAnchored, Reflectance, Color)
	local part = Instance.new("Part")
	part.BrickColor = BrickColor.new(Color) 
	part.Reflectance = Reflectance
	part.Anchored = IsAnchored 
	part.Name = name 
    part.Parent = workspace
end 

The reason why it’s erroring is because you have to use BrickColor.new, also you have a few unnecessary parenthesis and using ("name") will set both part names to "name" and not the actual argument passed

2 Likes
  1. It’s bad practice to set the parent of a new instance directly, you should alter the properties and then parent it to workspace.

  2. Putting a parenthesis around the parameter when assigning it to something is redundant, you shouldn’t do it.

  3. It’s better practice to use local functions wherever you can.

  4. The property is Name and not name, it’s case sensitive.

  5. The BrickColor property only accepts BrickColor datatypes.

  6. When asking for help, provide the code (not through screenshots), give some context, and state what error pop ups, if there are any.