Packet - Networking library

Hey guys, I’m trying to implement Packet with parallel luau but there seems to be an issue when assigning the server script to an actor and calling the Packet Module that I created (HelpProblem module). This one:
image

When calling the HelpProblem module in an actor it seems to create another RemoteEvent. Now this will work if there is only 1 actor which might seem fine but when I added another actor that does the same thing and tried to run it I get this message:


image

The second actor always returns this error for some reason and I think the reason is because of the duplicate RemoteEvents that is being created? Not too sure.

I want to mention that I called task.synchronise() when calling the HelpProblem module in the server script so it shouldn’t be able to fire the packet module while in parallel (and I think firing events in parallel is illegal in Roblox so it wouldn’t work anyways).

The duplicate RemoteEvents only appears when it is inside an actor and creates a new one for every new actor that calls the Packet Module (HelpProblem module) so when I have multiple scripts that calls the HelpProblem module outside the actors it only uses 1 which is expected:
image

Then in test 2 I tried creating a module script (CallAtOnePlace module) so that the scripts in the actors can access one point instead of calling them in each actor individually but it also didn’t work:

In theory all these should create one RemoteEvent only since its still running serially on the main thread, but instead it create’s multiple RemoteEvent’s.

Right now my current solution is to just create another RemoteEvent in ReplicatedStorage and directly sending it to the client.
I’m not sure if there is a way to get around this using Packet but please let me know! Thanks for reading! :slight_smile:

Here is the Place file if you want to test:
HelpProblem.rbxl (73.8 KB)

I want to mention that I commented out task.wait() in one of the Actors to show the error, but enabling/uncommenting it should work the same, I did this because it spams the output a little bit and to make it easier to see the error.

Also I apologise for the many edits, I initially created this post on mobile then moved to PC to finish it along with the errors in the post :pray: :face_holding_back_tears:

Thanks for reporting this problem ill try to add actor support in the next update but it could be problematic because each actor wont be able to share the same buffer and so it wont be able to batch events from each actor together

Now im no expert but uhm


is this supposed to happen? Shouldnt it simplify it as one call? Or does it add one per key (event)?
If it should work like this then just heart this message instead of replying to save everyone some effort lol

image
(here the same event is used 3 times at once)

correct this is not supposed to happen it should be simplified to one call unless your using actors

would you mind sharing how you managed to do this?

1 Like

Sure thing, I kinda copied something from your video, maybe I did it wrong?


This is a module which is requested every time I need access to a packet.

Ok this part looks fine how are you firing them?

image
this would be an example. I do it like this from all of the scripts in need of remote eventing.

There will be a call per player so if your firing to 4 players then there would be 4 calls

Ah! That makes sense. And I assume this is intended? Or am I messing up the module somehow? (heart if its intended so that we dont flood replies)

if there really is 4 players then that is intended it would not be possible otherwise

if you don’t have 4 players and its still calling 4 times then something is messed up

1 Like

Oh wait youre right i didnt even think about that. I was alone :sob:


Team Test (Alone) (Roblox Server)

image
Local testing session (not roblox server)

Seems this happens generally, so its not some weird “server-client-boundary-mix”-messup. In that case I naturally assume it has something to with my code.

Theory;

The “Packets Module”


I require a lot creates new packet instances every time it is required (so once per script) instead of re-using already exisiting ones.

Are you using actors?

this is how it should look

are here we can see 2 scripts firing

and we can still see they still get batched


Edit

Ok I think I replicated the problem let me see if I can find why its doing it

I think it is happening because when you fire a event every frame it does not always mean the client will read them both in separate frames the event can reach the client on the same frame

1 Like

oh wow I’m emberassed to say that most of the used scripts were in an actor (i didnt even know :sob:)
I searched for all actors (using classname=“actor” in the search bar) and moved the scripts but it still appears to be uhh… doing it


Ill check for more scripts that may be somewhat hidden in their actors

EDIT: I didnt find any other actors. Also if I might add it seems like both of these calls came from the same script anyways (awfully similar buffers), in which case (I believe) it wouldnt even matter if they were parented to an actor.


notice how there are gaps this is because each event does not have a fixed time
so by the time the client gets the event multiple events can overlap one another

but when we add a small delay

the events no longer overlap

so in short this is not a problem its fine

the only way we could stop that from happing would be to batch multiple frames but then it would introduce extra latency and I would not want to do that

1 Like

Can’t say I mentally get it but if its fine its fine :slight_smile:

Thank you for your help and this free resource :slight_smile:

Do you have to state all the key names and their types for a dictionary like in your example?

local packet = Packet("Dictionary", {Key = Packet.NumberF32, AnotherKey = Packet.String})

I have a data template for my data system and wouldn’t like to manually add the keys and values to multiple scripts when I add new data.

You can make a shared module that returns a table listing all of the packets.
For example:

local packet = require(script.Packet)

return table.freeze({
	MyEvent = packet("MyEvent", packet.Instance)
})
1 Like

In the video I also show how to make a module where you can define the packets just once like Alexander just said

I found an error. If your packet is not registered on the server, packet.Id will not be set.

An easy fix would probably just be to place an

if not self.Id then
    error("Packet '"..self.Name.."' is not registered on the server!", 3)
end

in the :Fire() function.