# Environment

All Roblox games, including RetroStudio, have their own **environment** where your parts, models, scripts, etc. are stored. You are likely aware that your game's main content is stored in `Workspace`.

It is often important to interact with the environment by adding new objects, modifying or deleting existing objects. This is done using **indexing**.

Indexing involves using a "path" to get to a certain object or property. Paths can begin from `game`, `workspace`, or a variable containing an object.

Let's say that we want to make a part in Workspace called "Block" red. Here's how you would do it:

```lua
workspace.Block.BrickColor = BrickColor.new("Really red")
```

`workspace.Block.BrickColor` means that you want to set the `BrickColor` property of `workspace.Block`, and that you want to set it to `BrickColor.new("Really red")`, which creates a BrickColor with a red color.

But what is BrickColor? It is a **special type** that represents **a color**. We will go over special types like it in a separate page.

***

As you might have guessed, we can not only modify existing objects, but also create new ones. This is done using the `Instance.new()` function. Note that the "I" in Instance is capitalized.

Let's adapt our previous example to create a new part instead of using an existing one:

```lua
block = Instance.new("Part", workspace)
block.Name = "Block"
block.BrickColor = BrickColor.new("Really red")
```

The first line will create a **Part** in **workspace**, and assign it to the variable **block**.\
The second line will rename the part to be called **Block** (therefore accessible as workspace.Block).\
The third line will set the part's **BrickColor** to **Really red**.

As you noticed, `Instance.new()` takes two arguments: the **type** of the object you want to create, and **where you want to put the new object**.

***

Each object also has its own **functions**. These functions can do special operations with the object, such as deleting or cloning it. Let's take a look at how we can **delete an object**:

```lua
workspace.Block:Destroy()
```

Therefore, if you have a part called "Block" in workspace, this code will delete (or "destroy") it. **Note the usage of : instead of .** before `Destroy()`. This is because the : character signifies that the function has to be performed on an object.

{% hint style="info" %}
In Lua, `workspace.Block:Destroy()` is functionally identical to `workspace.Block.Destroy(workspace.Block)`. The latter usage of the function is not supported in Powerlang due to compiler limitations.
{% endhint %}

You can use this Roblox Documentation webpage to determine what operations you can do with objects: <https://create.roblox.com/docs/reference/engine/classes/Instance> (Note that newer functions will not work, as RetroStudio is focused on delivering an old Roblox experience).

***

In the next page we will discuss special types and see more ways of using them.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vopwn55.gitbook.io/powerlang-docs/beginners-guide/environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
