# Installation

## Open Ports

This guide explains how to allow **port 3737** for **both TCP and UDP** traffic, for **Inbound and Outbound** directions, using **Windows Defender Firewall**.

{% hint style="info" %}
You can change the port on which the script will run using the `tgiann_stats_http_host` command. Simply add the following code to your server cfg

```
set tgiann_stats_http_port "3737"
```

{% endhint %}

### Requirements

* You must run the commands in **Command Prompt (CMD) or PowerShell as Administrator**.

### Open TCP 3737 (Inbound)

```bat
netsh advfirewall firewall add rule name="FiveMStats - TCP 3737 - In" dir=in action=allow protocol=TCP localport=3737
```

### Verify Rule

To confirm the rules exist:

```bat
netsh advfirewall firewall show rule name="FiveMStats - TCP 3737 - In"
```

### Remove Rules (Rollback)

If you need to delete the rules later:

```bat
netsh advfirewall firewall delete rule name="FiveMStats - TCP 3737 - In"
```

### Notes

* These commands configure **Windows Defender Firewall only**.
* If you are using a hosting provider, VPS panel, or additional DDoS/firewall layer, you may also need to allow port **3737** there.
* Ensure the application/service is actually listening on port **3737** on the server.

***

## FiveMStats Script Installation Guide

This guide explains how to install and connect the **tgiann-fivem-stats-script** to **fivemstats.net**.

***

### 1. Download the Script

* Download **tgiann-fivem-stats-script** from your **CFX Portal account**.
* Make sure you have the latest version.

***

### 2. Install the Script

1. Upload the script to your server’s **resources** folder: `resources/tgiann-fivem-stats-script`
2. Add the script to your server.cfg: `ensure tgiann-fivem-stats-script`
3. Restart your server (or ensure the resource).

***

### 3. Configure the Secret Key (IMPORTANT)

1. Open the server.cfg
2. Add the following code to the section before the scripts start, changing the key part.

```
set tgiann_stats_secret_key "your-secret-key-here"
```

#### Security Notice

* **This key is used to authenticate your server with FiveMStats**
* **Never share this key** with anyone
* If the key is leaked, regenerate it immediately and update both:
  * Server cfg change code
  * The FiveMStats dashboard

***

### 4. Add Your Server on FiveMStats

1. Go to [Fivem Stats My Server Page](https://www.fivemstats.net/dashboard/my-servers)
2. If you are not logged in, **sign in with Discord**.
3. Click the **“Add Server”** button.

***

### 5. Fill in Server Details

You will see the **Add New Server** form.

#### Fields Explanation

* **Server Name**\
  A display name for your FiveM server

```
-- Example
My FiveM Server
```

* **Server IP Address**\
  Enter your server IP and FiveM port

```
-- Example
123.456.789.0
```

* **Secret Key**\
  Paste the **same Secret Key** you added in `server.cfg`

```
-- Example
wO9ba1dbAG1JVAZGWjgiTefLob7wZ6GN
```

4. Click **Add Server**

***

### Troubleshooting

* Server not connecting?
  * Check firewall / DDoS protection
    * The website of the provider from whom you purchased the vps, vds etc usually has firewall settings. Make sure port 3737 is added in the settings.
  * Verify the Secret Key matches exactly
  * Ensure the resource is started
  * Check server console for errors
  * FiveMstats does not work on local servers. Do not try it on local servers.
