ByteNet
ByteNet copied to clipboard
Sending data when player joins causes an error
When you send data immediately after a player joins, an error is produced: ReplicatedStorage.ByteNet.process.bufferWriter:148: attempt to index nil with 'size'
The code used:
local ByteNet = require(game.ReplicatedStorage.ByteNet)
local packets = ByteNet.defineNamespace("a", function()
return {
Test = ByteNet.definePacket({
value = ByteNet.bool;
});
}
end)
game.Players.PlayerAdded:Connect(function(player: Player)
packets.Test.sendTo(true, player)
end)
You can fix this for now by using task.defer:
Players.PlayerAdded:Connect(function(player: Player)
task.defer(packets.Test.sendTo, true, player)
end)
A possible fix on the library side would be checking if the channel exists when firing data, however not including it is a microoptimization and it depends on ffrostfall whether it should be added or not
function serverProcess.sendPlayerReliable(
player: Player,
id: number,
writer: (value: any) -> (),
data: { [string]: any }
)
if not perPlayerReliable[player] then
perPlayerReliable[player] = create()
end
perPlayerReliable[player] = writePacket(perPlayerReliable[player], id, writer, data)
end
-- and the same for `sendPlayerUnreliable`