ModuleScript.Source won't write string

I’m experiencing with the BitBuffer module from:

https://dekkonot.github.io/bitbuffer/ / BitBuffer Documentation

And I tried to write the example use (found on Writing - BitBuffer Documentation) with kind of success, but it won’t let me write it to a ModuleScript source. This is basically the script:

local data = {
	name = "John Doe",
	health = 100,
	maxHealth = 100,
	points = 10,
	position = {
		x = 10.55915,
		y = -15.2222,
	},
	bossesKilled = { true, false, true },
}

local BitBuffer = require(game.ServerStorage.BitBuffer) -- The BitBuffer should be required here.

local buffer = BitBuffer()

buffer.writeString(data.name)
buffer.writeUInt16(data.health) -- This is assuming someone's health will get above 255 but stay below 32,767
buffer.writeUInt16(data.maxHealth)
buffer.writeUInt16(data.points) -- Also assuming someone's points will stay rather low
buffer.writeFloat32(data.position.x)
buffer.writeFloat32(data.position.y)
buffer.writeField(table.unpack(data.bossesKilled))

-- To do the math: 11 bytes for name (length prefix + raw bytes), 2 each for health, maxHealth, and points, 
-- 8 for position, and an extra 1 for bossesKilled (though you could write 5 more bools without loosing any space!). 
-- 11+6+8+1 = 26

local output = buffer.dumpString()

local bv = Instance.new("ModuleScript")
bv.Parent = game.ServerStorage
bv.Name = "Compiled?"

bv.Source = output

I’m running this code from the command bar. When I print:

print(output)

It does show me the compiled output string:
image

But the module script just remains empty.

Does anyone know why this is? I’ve seen multiple people work with BitBuffer so I don’t really understand why this doesn’t function correctly for me.

Thanks for the reply!

Have you tried string.pack and string.unpack? Those work pretty well over the BitBuffer module.

Edit: oh, I thought you were using an older version.

https://developer.roblox.com/en-us/api-reference/property/ModuleScript/Source

1 Like

I’m executing from the command bar, if that is what you are referring to.

But you’re assigning a string to the source attribute in the script, aren’t you?

Yeah I’m assigning the Source attribute of the script.

If I would insert any string, it would insert it into the source, but the bitbuffer output doesnt, thats the main issue

You can’t insert into the source from another script, you can only do that from command bar and plugins.

I have a gut feeling that he knows.

The only issue I’m having is that it doesnt put the BitBuffer output in the script.

If you check what is the first character of the output string, for example by using

print(string.byte(output))

you will notice that it has the ascii code 0, which is a Null character, or “\0”. It is used in a string to show where it ends, that is why, when you assign that output to the Source attribute - your module will be empty.

You can try:

module.Source = "test1 \0 test2"

And in your module you will only have “test1”, because Roblox treats “\0” as an ending of a string, therefore it doesn’t read anything beyond that.