# Shared

## Using Cosmoble

In order to begin using Cosmoble you will first need to fetch it, you can do this using `require()`.

<pre class="language-lua"><code class="lang-lua"><strong>local Cosmoble = require(game:GetService("ReplicatedStorage").CosmobleShared
</strong></code></pre>

## Getting a Cosmoble's Data

When you want to get the Cosmoble data via client, use the `get` and provide a Cosmoble name in order to get it, if data exists it will return a **table** containing it.

{% hint style="danger" %}
It is not recommended to use this function a lot, a cache is recommended.
{% endhint %}

<pre class="language-lua"><code class="lang-lua"><strong>Cosmoble.get("cosmobleName") -- Returns a table.
</strong></code></pre>

## Connecting to a Cosmoble

When connecting to a Cosmoble via client, use the `connectCosmoble` function with the arguments below.

`cosmobleName` - `string`: The name of the `Cosmoble` table to connect to.

`theConnection` - `string`: A unique name for the connection.

`function(key, value)` - a callback `function` that will be called whenever a change is detected in your game data

```lua
Cosmoble:connectCosmoble("cosmobleName", "theConnection", function(key, value)
    print(key.." changed to "..value
end)
```

## Disconnecting from a Cosmoble

When you are finished using a Cosmoble, you should disconnect from it using the `disconnectCosmoble` function with the arguments below, this will stop calling your connected function.

`cosmobleName` - `string`: The name of the Cosmoble table that you want to disconnect from.

`connectionName` - `string`: The unique name of the connection that you want to disconnect from.

```lua
Cosmoble:disconnectCosmoble("cosmobleName", "connectionName")
```
