[ARCHIVED] FastNet2 - a fast, efficient & lightweight network library

Whenever I fire a remote it doesn’t send a callback.

can u sent the code, i will look on it if there issue on the code or backend

-- Server
--!strict

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FastNet2 = require(ReplicatedStorage:WaitForChild("FastNet2"))

local testRemote = FastNet2:Create("TestRemote", "RemoteEvent")
testRemote:Listen(true, function(...)
	print(...)
end)
--Client
--!strict

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FastNet2 = require(ReplicatedStorage:WaitForChild("FastNet2"))

local testRemote = FastNet2:Create("TestRemote", "RemoteEvent")
testRemote:Fire("E")
1 Like

i will be releasing the patch (this issue fixed), im checking on other sides before release the patch

Commit - BugFix


Also available on file download format

new v0.0.8-refresh (build_8.1) published to wally as v0.0.81 version

Wally - FastNet2_v0.0.81

1 Like

Commit - 8.2

Available on file format (download)

what
image

--!strict

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

local FastNet2 = require(ReplicatedStorage:WaitForChild("FastNet2"))

local longInputBeganEvent = FastNet2:Create("LongInputBeganEvent", "RemoteEvent")
local inputEndedEvent = FastNet2:Create("InputEndedEvent", "RemoteEvent")
local inputBeganEvent = FastNet2:Create("InputBeganEvent", "RemoteEvent")

local character: Model?, player: Player?, humanoid: Humanoid?, torso: Instance?, rightArm: Instance? = nil, nil, nil, nil, nil
local connections: {RBXScriptConnection} = {}

local uuid = FastNet2.CreateUUID()
local equipThread: thread? = nil

local tool = script.Parent
local equipped = false

local function onWeaponActivateBegan(playerWhoActivated: Player, position: Vector3)
	if equipped and playerWhoActivated == player then
		print(position)
	end
end

local function onWeaponActivateEnded(playerWhoActivated: Player, position: Vector3)
	if equipped then

	end
end

local function onWeaponActivated(playerWhoActivated: Player, position: Vector3)
	if equipped then

	end
end

local function onUnequipped()
	if equipped then
		if equipThread then
			task.cancel(equipThread)
			equipThread = nil
		end
		for _, connection in ipairs(connections) do
			if connection.Connected then
				connection:Disconnect()
			end
		end
		table.clear(connections)
		character, player, humanoid, torso, rightArm = nil, nil, nil, nil, nil
		equipped = false
	end
end

local function onAncestryChanged(child: Instance)
	if not child:IsDescendantOf(game) then
		onUnequipped()
	end
end

local function hookChildrenOnParentChanged(children: {Instance})
	for _, child in ipairs(children) do
		if child:IsDescendantOf(game) then
			table.insert(connections, child.AncestryChanged:Connect(onAncestryChanged))
			table.insert(connections, child.Destroying:Connect(onUnequipped))
		end
	end
end

local function onEquipped()
	if not equipThread and not equipped then
		character = tool:FindFirstAncestorOfClass("Model")
		if character then
			player = Players:GetPlayerFromCharacter(character)
			humanoid = character:FindFirstChildWhichIsA("Humanoid")
			if player and humanoid then
				local rigType = humanoid.RigType
				if rigType == Enum.HumanoidRigType.R6 then
					torso = character:FindFirstChild("Torso")
					rightArm = character:FindFirstChild("Right Arm")
				elseif rigType == Enum.HumanoidRigType.R15 then
					torso = character:FindFirstChild("UpperTorso")
					rightArm = character:FindFirstChild("RightHand")
				end
				if torso and torso:IsA("BasePart") and rightArm and rightArm:IsA("BasePart") then
					equipThread = task.spawn(function()
						local rightGrip = rightArm:WaitForChild("RightGrip", 5)
						if rightGrip and rightGrip:IsA("JointInstance") then
							hookChildrenOnParentChanged({player, character, humanoid, torso, rightArm, rightGrip})
							table.insert(connections, humanoid.Died:Connect(onUnequipped))
							equipped = true
						end
					end)
				end
			end
		end
	end
end

tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
tool.AncestryChanged:Connect(onAncestryChanged)
tool.Destroying:Connect(onUnequipped)
longInputBeganEvent:Listen(true, onWeaponActivateBegan)
inputEndedEvent:Listen(true, onWeaponActivateEnded)
inputBeganEvent:Listen(true, onWeaponActivated)
tool:SetAttribute("UniqueId", uuid)
1 Like

its now fixed you can get the latest on github (just update with the init.luau source as “Replace 8.2” ← Commit)

Commit - 8.3
Second-Commit - 8.3

Available for file (download, updated to second-commit)

add second-commit (fix minor mistake)

That was fast I also fixed an issue were this module create 2 folders named Net:

-- At line 124 inside FastNet2
local Nets: any = script:FindFirstChild("Net")
if not Nets or not Nets:IsA("Folder") then
	if IsServer then
		local newNets = Instance.new("Folder")
		newNets.Name = "Net"
		newNets.Archivable = false
		newNets.Parent = script
		Nets = newNets
	else
		Nets = assert(script:WaitForChild("Net", 5), string.format("[%s]: Failed to get the Net folder. Did you forget to require this module on the server?", script.Name))
	end
end

local _NetEvent: RemoteEvent = Nets:FindFirstChild("Event")
if not _NetEvent or not _NetEvent:IsA("RemoteEvent") then
	if IsServer then
		local newNetEvent = Instance.new("RemoteEvent")
		newNetEvent.Name = "Event"
		newNetEvent.Archivable = false
		newNetEvent.Parent = Nets
		_NetEvent = newNetEvent
	else
		_NetEvent = Nets:WaitForChild("Event")
	end
end
1 Like

decided to migrating Pre-Alpha name to Dev in next version till Alpha

Commit - 8.4


Available for file (download), this version will be published to wally later

Also FastNet2 Benchmark place is updated with latest version and added Red

Added Red network library to benchmark result sample

Oh dang FastNet2 is always fast. Also is the previous issue fixed?

i already tested it and i dont see there duplicated net folder issue

image
This only happens on the client

can u show your client code because i tested with double requiring and different localscript requiring it still not, make sure before you run the place check the fastnet2 if there Net folder, if there exist then delete it

I tested by requiring the module both server and client

--!strict
-- Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local FastNet2 = require(ReplicatedStorage:WaitForChild("FastNet2"))
--!strict
-- Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local FastNet2 = require(ReplicatedStorage:WaitForChild("FastNet2"))