Skip to content

Network API Rework & New Server Hooks

Latest

Choose a tag to compare

@Nextinel Nextinel released this 09 Nov 08:08
· 6 commits to main since this release
f3b4268

Network API

  • Added support for separate remote and invoke configurations inside the module's network table. You can define either entry independently or use both. Remote Events are handled through onEvent, while Invoke requests are handled through onInvoke
  • onEvent handles both reliable and unreliable remote events automatically
  • Added client methods :fireServerUnreliable() and :invoke()
  • Added per-player Invoke rate limits and a limit for concurrent Invoke requests
  • contract and shouldCheckExtrafields are still supported - they just moved inside the remote/invoke tables

New Server Hooks

  • characterAppearanceLoaded - called when a character's appearance finishes loading (server hook)
  • onServerRestartScheduled - called when a server restart is scheduled (server hook)
  • bindToClose - called when the server is shutting down (server hook)

Note: Roblox gives a maximum of 30 seconds for bindToClose to finish. Keep your logic lightweight (e.g., just save data)

Protected Require

  • Module require errors are now caught. The framework will print a warn in the output with the exact name of the module that failed to require

Nextinel Builder

  • Added Update Structure button for updating existing Framework scripts

Demo

Try it: Wave Survival (Download) - a small showcase of Nextinel in action. Covers networking, module lifecycle, profiles, and data saving

Notes

Updating from v2.x to v3.0.0:

  1. Update the plugin first. The Update Structure button only exists in the v3.0.0+ plugin
  2. Click Update Structure. It will list the old Framework scripts (Global, Server, Client, etc.) that need to be removed
  3. Delete those scripts. You don't need to delete anything inside Initialize folders
  4. Click Create Structure to generate the new v3.0.0 files

Before deleting scripts, make sure to save any important data and custom changes

Future updates: After installing v3.0.0, you can simply use Update Structure for all upcoming updates

Before / After

Before

return {
	network = {
		channel = "MyChannel",
		contract = {...},
		onEvent = function(plr, ...) end,
	},
}

After

return {
	network = {
		remote = {
			channel = "MyChannel",
			contract = {...},
			onEvent = function(plr, ...) end,
		},
		-- invoke is optional, add it only if you need it
		-- invoke = {
		--     channel = "MyInvokeChannel",
		--     onInvoke = function(plr) return end,
		-- },
	},
}

Examples

Server

local Types = require("@game/ReplicatedStorage/Modules/Global/Types")
local Jolt = require("@game/ReplicatedStorage/Modules/Global/Jolt")

local remoteChannel = Jolt.Server("RemoteChannel")
local invokeChannel = Jolt.Server("InvokeChannel")

return {
	network = {
		remote = {
			channel = "RemoteChannel",
			
			--shouldCheckExtrafields = false,
			--contract = {...},
			
			onEvent = function(plr, ...)
				-- ...
			end,
		},
		
		invoke = {
			channel = "InvokeChannel",
			
			--shouldCheckExtrafields = false,
			--contract = {...},
			
			onInvoke = function(plr)
				return -- ...
			end,
		}
	},
	
	playerAdded = function(plr)
		remoteChannel:Fire(plr)
		remoteChannel:FireUnreliable(plr)
		
		local a, b, c = invokeChannel:Invoke(plr)
	end,
} :: Types.ServerModule

Client

local Types = require("@game/ReplicatedStorage/Modules/Global/Types")

local channels: {[string]: Types.NetworkObject} = {}

return {
	network = {
		remote = {
			channel = "RemoteChannel",
			
			--shouldCheckExtrafields = false,
			--contract = {...},
			
			onEvent = function(...)
				-- ...
			end,
		},
		
		invoke = {
			channel = "InvokeChannel",
			
			--shouldCheckExtrafields = false,
			--contract = {...},
			
			onInvoke = function()
				return -- ...
			end,
		}
	},
	
	setupFireServer = {
		channelsNames = {"RemoteChannel", "InvokeChannel"},
		
		setupChannel = function(name, networkObject)
			channels[name] = networkObject
		end,
	},
	
	init = function()
		channels.RemoteChannel:fireServer()
		channels.RemoteChannel:fireServerUnreliable()
		
		local a, b, c = channels.InvokeChannel:invoke()
	end,
} :: Types.ClientModule