I use ID’s to tell different “Pings” apart, but tbh that feels kinda hacky. Is there a different method of doing that?
If you spot something else off lmk!
Module:
local Remote = script.RemoteEvent
local Ping = {}
function Ping.new()
local self = setmetatable({},{__index = Ping})
--Add into pings
table.insert(Ping, self)
self.ID = table.find(Ping, self)
return self
end
function Ping:Connect(fn)
return Remote.OnServerEvent:Connect(function(Player, OtherID, ...)
if OtherID == self.ID then
fn(Player, ...)
end
end)
end
function Ping:Fire(...)
Remote:FireServer(self.ID, ...)
end
return Ping
It is indeed somewhat hacky. What I suggest doing if you want the ID to just be a unique identifier is to get a uniqueID from HttpService with: HttpService:GenerateGUID(false).
Updated code:
local HttpService = game:GetService("HttpService")
local Remote = script.RemoteEvent
local Ping = {}
function Ping.new()
local self = setmetatable({},{__index = Ping})
--Add into pings
table.insert(Ping, self)
self.ID = HttpService:GenerateGUID(false)
return self
end
function Ping:Connect(fn)
return Remote.OnServerEvent:Connect(function(Player, OtherID, ...)
if OtherID == self.ID then
fn(Player, ...)
end
end)
end
function Ping:Fire(...)
Remote:FireServer(self.ID, ...)
end
return Ping
HTTP service UUID is very bad aproach for networking, as it generates 34 bytes of information, this kind of data isn’t very nice to have sent over remotes, as it will make bandwidth skyrocket
What he can do instead is using numbers as UUIDs, this way he will only use 8 bytes of data, and even then, he can use 16bit buffer to handle his IDs and re-use them if needed, 16bits can handle up to about 64k numbers, which is usually more than enough