> ## Documentation Index
> Fetch the complete documentation index at: https://playwave.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# isPcCafeUser Debug Script

> Periodically prints PlayWaveServer.isPcCafeUser to verify session state and PC cafe detection.

A debug script that periodically logs the return value of `PlayWaveServer.isPcCafeUser(player)` so you can verify that session state and PC cafe detection are wired up correctly.

## Install

<Steps>
  <Step title="Open your project in Roblox Studio" />

  <Step title="Create a new Script under ServerScriptService">
    Right-click → `Insert Object` → `Script`.
  </Step>

  <Step title="Rename it to PlayWaveDebug" />

  <Step title="Paste the code below">
    ```lua theme={null}
    -- PlayWaveDebug (Server Script, ServerScriptService)
    local Players = game:GetService("Players")
    local ServerScriptService = game:GetService("ServerScriptService")

    local PlayWaveSetup = ServerScriptService:WaitForChild("PlayWaveSetup")
    local PlayWaveServer = require(PlayWaveSetup:WaitForChild("PlayWaveServer"))

    while true do
        local players = Players:GetPlayers()
        if #players == 0 then
            print("[PlayWaveDebug] no players")
        else
            for _, player in ipairs(players) do
                print("[PlayWaveDebug] isPcCafeUser:", player.Name, "->", PlayWaveServer.isPcCafeUser(player))
            end
        end
        task.wait(3)
    end
    ```
  </Step>
</Steps>

## Code walkthrough

### `game:GetService("...")`

The standard way to access Roblox built-in services. `Players` manages connected players; `ServerScriptService` is the container for server-side scripts.

### `ServerScriptService:WaitForChild("PlayWaveSetup")`

Looks for a child of `ServerScriptService` named `PlayWaveSetup`. If it does not exist yet, **waits until it appears**.

Why `WaitForChild` instead of `ServerScriptService.PlayWaveSetup`:

* Scripts under `ServerScriptService` start executing **in parallel** and load order is not guaranteed.
* If this debug script runs before `PlayWaveSetup`, the `PlayWaveSetup` instance may not be in the tree yet.
* `.` direct access → errors immediately if the child is missing.
* `:WaitForChild()` → yields until it exists.

Think of it as **"a safe accessor that walks the instance tree."**

### `require(ModuleScript)`

Roblox's module loader. The target must be a `ModuleScript`, and:

1. On the first call → runs the script once and caches the value returned via `return`.
2. On later calls → returns the same cached value without re-running the script.

```lua theme={null}
local A = require(PlayWaveServer)  -- first call: module runs
local B = require(PlayWaveServer)  -- returns the cached table
-- A and B are the same table. Setting A.foo = 1 also sets B.foo = 1.
```

This is why **state is shared across scripts that require the same module.** It's also why this debug script can read `activeSessions` populated by `init()` in `PlayWaveSetup`.

### `PlayWaveSetup:WaitForChild("PlayWaveServer")`

Waits for the **`PlayWaveServer` ModuleScript** nested under the `PlayWaveSetup` Script. The actual tree:

```
ServerScriptService/
  PlayWaveSetup          (Script)        ← required here
    ApiKey               (StringValue)
    ApiUrl               (StringValue)
    PlayWaveServer       (ModuleScript)  ← require target
```

### `while true do ... task.wait(3) end`

Infinite loop that yields every 3 seconds via `task.wait(3)`. Without `task.wait`, a bare `while true` **blocks the server scheduler**, freezing every other script and event.

### `Players:GetPlayers()`

Returns an array of currently connected `Player` instances. `#players` is the array length.

## Run

Press **Play** in Studio and watch the **Output** window — a log line prints every 3 seconds.

## Expected output

### Server only (no players)

```
[PlayWaveDebug] no players
[PlayWaveDebug] no players
...
```

### Right after a player joins (before OTT verify)

```
[PlayWaveDebug] isPcCafeUser: Player1 -> false
```

There is a short delay between join and the OTT API response, so the initial value may be `false`.

### After OTT verify completes (regular user)

```
[PlayWaveDebug] isPcCafeUser: Player1 -> false
```

Regular users stay at `false`.

### After OTT verify completes (PC cafe user)

```
[PlayWaveDebug] isPcCafeUser: Player1 -> true
```

PC cafe users flip to `true` and stay there. A `[PlayWave] PC cafe detected` log line appears alongside.

### Teleported into a subplace

```
[PlayWaveDebug] isPcCafeUser: Player1 -> true
```

Session state from the previous server is forwarded via `TeleportData` and applied immediately.

## Troubleshooting

<AccordionGroup>
  <Accordion title="attempt to call a nil value" icon="circle-exclamation">
    `PlayWaveServer.isPcCafeUser` does not exist on the module. **Your SDK is out of date.**

    Fix:

    1. Overwrite the plugin file with the latest `PlayWavePlugin.plugin`:
       * macOS: `~/Documents/Roblox/Plugins/`
       * Windows: `%LOCALAPPDATA%/Roblox/Plugins/`
    2. Restart Studio.
    3. Run **PlayWave Setup** → **Install SDK** again from the toolbar.

    <Warning>
      Reinstalling resets any edits to the `PlayWaveSetup` script. Back up customizations such as the `onPcCafe` callback first.
    </Warning>
  </Accordion>

  <Accordion title="Infinite yield possible on WaitForChild('PlayWaveSetup')" icon="hourglass">
    `WaitForChild` waited more than 5 seconds without finding the target. **The SDK is not installed.** Run **Install SDK** from the toolbar.
  </Accordion>

  <Accordion title="Always returns false (testing as a regular user)" icon="circle-check">
    Working as intended. PC cafe detection only flips to `true` when the player joins through the PlayWave launcher in a PC cafe environment.
  </Accordion>

  <Accordion title="[PlayWave] No OTT found, skipping verify warning" icon="circle-info">
    The player joined without going through the PlayWave launcher. No session is created for this user, so `isPcCafeUser` always returns `false`. This is expected.
  </Accordion>
</AccordionGroup>

## Notes

<Warning>
  **Debug use only.** The 3-second interval floods production logs — disable or delete the script once testing is done.
</Warning>

* Adjust the cadence by changing `task.wait(3)` at the top of the script.

## Related API

* `PlayWaveServer.isPcCafeUser(player)` — returns a boolean. Returns `false` if no session exists.
* `PlayWaveServer.init({ onPcCafe = function(player) ... end })` — callback invoked once when a PC cafe user joins. Prefer this over polling if you want to grant rewards on join.
