It looks like you are inserting the ban in two different ways. The “hahafunnyban” is inserted as a dictionary entry but the “test” ban is inserted as an array entry. Instead of the last two lines insert the emptyBan like this.
Is this code running on the server or the client? Ban code has to run on the server so that a client can’t manipulate it. UI code has to run on the client so it can be displayed.
The data in ModuleScripts doesn’t replicate from the server to the client automatically (even though the same ModuleScript can be required from both sides). There needs to be a RemoteEvent or something which communicates the new bans to the client that you are viewing the admin on.
The code to add a new ban is running on the server
The code that shows the UI is running on the client
re requiring the module each time I refresh doesn’t update it
This UI resets every time the player respawns, wouldn’t adding a new text button from the remote event just be removed after they respawn?
Also what would I do on the client when I get the event? whenever a banned player button is clicked it pulls all of the information from the module, so nothing would actually be displayed when the new button is clicked, it would just be a useless button
It will need to be a RemoteEvent (or RemoteFunction). The module can be defined on both the server and the client but it won’t contain the same data on both.
There are several different ways to structure it but you definitely are going to need some remote communication to display this on the client side.
What you’re dealing with here is changing data that needs to be shared across all calls of this module script. What you could do is have a string instance in replicated storage(if you want the client to be able to see the bans but not edit them), or in server storage (if you want only the server to be able to see them). In that string instance you can store the JSONEncoded string of your data and manage it through the module.
If however you want the bans to persist across sessions and all running servers of your game, you will have to use datastores for permanent saves or memorystores in case the bans are only temporary, they can’t be longer than the maximum amount memory stores store data for, and the data per key isn’t much. If you want to mass fetch data you can try saving the info of multiple players under single keys, although that will make the system a bit more complex in nature.
The module fetches the value, deserializes it, manages it, then writes it back.
JSON was only used as an example here, you can store the data in an instance or multiple instances in any form you like, as long you know how to read and write to it. This is for in-game storage of data that isn’t large (basically here I assume that ban related data wont take many characters to be stored, because you add manually to it, not like a datastore that contains millions of keys).
I fixed it a different way
I fired an event to all clients whenever a new ban is added, along with a clone of the module from the server. On the client, I set the ban module to the clone, BanStorage = bansClone
This seems to be working.
This entire logic can be simplified by storing the data in ReplicatedStorage. ReplicatedStorage is visible on the client and any changes the server does to an instance (like a StringValue) there automatically replicate to all clients. Also when a new client joins, they get the latest version of this replication (the one other players have).
Basically it helps you get rid of this sort of code and you can use it for things like UI text (for example intermission text, announcements). All you have to do is run code once on player load for the current value of an instance and then rerun it when the replicated instance fires the .Changed event.