Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending data when player joins causes an error #22

Open
birds3345 opened this issue Jul 25, 2024 · 1 comment · May be fixed by #23
Open

Sending data when player joins causes an error #22

birds3345 opened this issue Jul 25, 2024 · 1 comment · May be fixed by #23

Comments

@birds3345
Copy link

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)
@Mark-Marks
Copy link

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants