Instance creation giving an error

So, I am trying to create an instance in workspace called part, but it gives me an error. I tried searching what’s wrong, but I found many more people who had this problem in more complex scripts that I can’t read. I know it’s underlining the dot behind “Size”. Does anyone know why?

Script:

local workspaceService = game:GetService("Workspace")

local instance = Instance.new("Part", workspaceService)
local instance.Size = Vector3.new(2, 2, 2)
local instance.Name = "Instancy"

Error:

ServerScriptService.Script:13: Expected identifier when parsing expression, got '.' 
1 Like

you shouldn’t put “local” everytime you’re changing properties, here do this instead.

local workspaceService = game:GetService("Workspace")

local instance = Instance.new("Part", workspaceService)
instance.Size = Vector3.new(2, 2, 2)
instance.Name = "Instancy"
1 Like

You only need to put local when you are creating a new variable. Changing the property of something doesn’t require that you put local

1 Like

But wouldn’t the “local” prevent the changes being done globally? I heard that you should use local whenever you can so that everything is clean and not crowded in the global scope.

Nope. It’s only the scope of the variable (namely, instance). The scope of the properties can either be client sided or server sided, which shouldn’t have much impact for you at this point.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.