Skip to content

Sending data when player joins causes an error #22

Open

Description

@birds3345

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)

Activity

  1. Mark-Marks commented on Aug 7, 2024

    @Mark-Marks

    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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions