Connectdocs

Settings

Luau
-- Setting
local synchronization = {
    port = 3000,
    base_url = "localhost",
    refresh_time = 10,
}
FieldTypeDescription
portnumberPort the server listens on. Default 3000.
base_urlstringHost of the server, without protocol. Use localhost when the server runs on the same PC.
refresh_timenumberSeconds between stats updates when you send them in a loop. See Stats → Refreshing.

Services

The script needs these Roblox services:

Luau
local http: HttpService = game:GetService("HttpService")
local rep: ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr: Player = game:GetService("Players").LocalPlayer
  • HttpService encodes messages as JSON.
  • Players.LocalPlayer gives the account info and the UserId used in the URL.

Connecting

The WebSocket URL is built from the settings plus the player's UserId:

URL
ws://{base_url}:{port}/connect/{UserId}
Luau
local ws = WebSocket.connect(
    "ws://" .. synchronization.base_url .. ":" .. tostring(synchronization.port)
    .. "/connect/" .. tostring(plr.UserId)
)
Heads up

The UserId in the URL identifies the connection. Always use plr.UserId, so it matches the userid you send in the link message.

Testing the connection

Plain strings can be sent too, which is handy for a quick check. Listen on OnMessage to see what the server replies:

Luau
ws:Send("Connected!")

ws.OnMessage:Connect(function(msg)
    print("Debug: ", msg)
end)