DynamicTables - Server->Client Replication for tables!

Features:

  1. You can get the length of your table even if its an array
local t = DynamicTables("MyTable")
t.owners = 10
t.active = false
t.price = 1000
print(#t) -- Prints 3!
  1. Your tables will replicate to clients automatically
--[[Server-Script]]
local t = DynamicTables("MyTable")
t.a = true
t.b = false
t.c = 100

--[[Local-Script]]
local t = DynamicTables("MyTable")
print(t.a, t.b, t.c) -- Prints true, false, 100
  1. You can use signals to listen to changes that are made to the table
local t = DynamicTables("MyTable")
t.health = 100
t:Changed("health"):Connect(function(old, new)
	print(`HP: {old}->{new}`)
end)
t.health = 50 -- Prints HP: 100->50

ExampleUsage:

--[["Server-script"]]
local DynamicTables = require(game.ReplicatedStorage.DynamicTables)
local myTable = DynamicTables("MyTable") -- this is how you get your table

myTable.Health = 10
myTable.Health += 250

--[["Local-script"]]
local DynamicTables = require(game.ReplicatedStorage.DynamicTables)
local myTable = DynamicTables("MyTable")
print(myTable) -- prints 260

PropertyChanged support:

myTable:Changed("Health"):Connect(function(oldHealth, newHealth)
	print("Health:", newHealth)
end)

NestedTables support [Removed in V0.03]:

myTable.SecondTable = {
	ThirdTable = {Coin = 50},
}

myTable.SecondTable.ThirdTable:GetPropertyChangedSignal("Coin"):Connect(function(coin)
	print("Coin:", coin)
end)

myTable.SecondTable.ThirdTable.Coin += 25

Attention:

if the module doesn’t work for you, try using this forked version which uses bytenet instead of bridgenet2, I will never be able to access studio again so I cant update this module myself.

Download:

Roblox Marketplace

Benchmarking results:


image

CustomInstance is my other module that lets you add custom properties to objects

29 Likes

UPDATE:

  • added a cooldown to server-client replication to make the module usable in expensive loops!

now you can read the source code in this github repo:

3 Likes

UPDATE:

  • Rewrote the module
  • 1.5x faster
  • Optimized server->client replication
  • Removed support for nested tables, simply said: you cant use :Changed() on tables that are inside a DynamicTable

GET:

2 Likes

UPDATE:

  • Default methods (Changed and GetData) that are added by the module will now be ignored when getting length of a dynamictable or using a for i, v loop
local t = DynamicTables("Test")
t.A = true
t.B = false

print(#t) -- Prints 2

for i, v in t do
	print(i, v)
	--[[
	Prints:
		A true
		B false
	]]
end
3 Likes

UPDATE:

  • getting the length of a table and using a for loop on it should be 60% faster now

Issues with this version:

  • the index in for loops will return numbers even if your table is an array (fixed it in 0.04-1)
1 Like

cant i just go to a server script and just do

remotefunc.OnServerInvoke = function(plr)
return tablename
end

like why would i use a module instead of doing that?

well you’re sending a whole table to the player by doing this which will result in having a high recv, my module only sends the part of the table that is being updated
so if you care about optimization then there is nothing wrong with using my module

3 Likes

this looks promising, I would need support for bulk actions for optimizations. If i have a game where a player can bulk sell 500 items at once, i dont want to do 500 remotes at once for it

3 Likes

Release 0.05

updates now happen every frame instead of every time the index changes
this is good for changing lots of items in the table all at once because it prevents remote event spamming

I honestly just wanted to rewrite the module but got stuck trying to make nested tables work so I gave up and just updated the module

2 Likes

for some reason, this simply doesn’t work for me.
I tried with both color3s and strings, and neither of them replicated. the :Changed signal didn’t even fire

i also tested by printing the length of the table every frame
on the client, it stays at 0 even though i’m changing like 2 things inside the table every frame on the server

edit: after a bit of thinking i have a hunch that it’s from parallel coding
but i can’t say for sure yet

edit 2: after testing, nope, whatever i put in gives me nil no matter what i do

are you using the 0.05 version? last time I worked on it it was working fine.
also, since Roblox studio is banned in my country I can’t update the module (I don’t remember if it is updated or not) on the marketplace so you have to get the rbxm file from the GitHub repo

i did get it from the github repo
it still didn’t work for me

Is there a way to make it so the first initial setup doesn’t fire the changed?

somehow, i got it to work by replacing BridgeNet2 with ByteNet (apparently made by the same dude who made BridgeNet2)

here’s the edit that worked for me
i still don’t know why this works while the original doesn’t but oh well

DynamicTables but i changed it or smth - Creator Store (roblox.com)

1 Like