Moderation panel data store help

I’m trying to make a data store system for my moderation panel so I can easily make a GUI that shows all the previous punishments of a player.
I want to make it so it saves the moderator, reason, suspect and punishment type.

I wanna make something that loops through the table and clones a pre-made GUI into another GUI with all the info from the datastore on it.

Unfortunately, I have no idea how data store works so I wanna ask for help on how to make something that saves all the data and gets the data if it’s needed, and also displays if someone has multiple punishments of the same type.

1 Like

How to use DataStores


Its crucial to understand what datastores are and how they work. If one step is done incorrectly then all data could be lost.

There are three types of datastores, Normal, Ordered, and Global.

Global Datastores


These are basically 1 datastore which is accessable without specifying a datastore name. I myself barely ever use this so I won’t go into full detail about this one.

Ordered Datastores


This datastore is basically a number based datastore, allowing you only to save Number values to a key. This specific datastore type has bonus methods such as IncrementAsync, and GetSortedAsync.

This data store is most commonly used for leaderboards or count saving.

Normal Datastores


This is the most common datastore you’ll find and ever use. This datastore allows you to save the following for each key:

  • Numbers
  • Strings
  • Booleans
  • Tables (either full array or full dictionary, cannot be mixed)
  • Nil

Saving Data


There are two different ways to save data on datastores. SetAsync, Which is slightly slower but gets the job done, and UpdateAsync which gives you better control over your data.

Getting the datastore:

This is how you get all datastores :

local DataStoreService = game:GetService("DataStoreService")
local DataStoreName = "PanelData" --| Replace with datastore name

local DataStore = DataStoreService:GetDataStore(DataStoreName) --| Normal
local DataStore = DataStoreService:GetOrderedDataStore(DataStoreName) --| Ordered
local DataStore = DataStoreService:GetGlobalDataStore() --| Global

Saving on the datastore:

This method saves data straight to the key.

local Key = "Warnings" --| All values will convert to string
local Data = { Warns = 0, UserId = 1 } --| Data doesn't have to be a table.
DataStore:SetAsync(Key, Data) --| Key (Name of data being saved), Data (What you're saving)

Updating on the datastore:

I prefer using this method for saving data, for it grants you the ability to check the current data and apply that to the new data without requiring to get the data first.

local Key = "Warnings"

DataStore:UpdateAsync(Key, function(pastData)
    local currentWarnings = pastData.Warns --| Can read past/current data
    local currentUserId = pastData.UserId  --| Can read past/current data

    local newData = { --| The new data (Doesn't have to be a table)
        Warns = 0,
        UserId = 1,
    }

    return newData --| Return nil to cancel or a value to replace the current data.
end)

Getting data from a key:

local Key = "Warnings"
local Data = DataStore:GetAsync(Key) --| Gets the data

The text above explains what and how you use datastores. Try applying them to your panel, especially the normal datastores. Just keep in mind that there is a limit on how many requests for both saving and getting at a time and will drop any further requests if the queue is full.

Thank you for your long answer but I still have a few questions.
How can I add for example the reason of the warning and also the moderator who warned the person and also would it be possible to store other types of punishments like bans and kicks within the same datastore? Also how do I list these warnings because I have a scrolling frame where a script copies all the warnings with their own cards showing the moderator the reason and the type of punishment. Lastly I have a question because I saw you used “Warns = 0” which makes me think it stores a number of how many warnings were given but I would like to save multiple warnings, kicks and bans so that my script creates a separate card in the UI for each warning, kick or ban showing who the moderator, reason and the punishment type is so could you explain how to do that?

You can basically save all of what you said in a table, but they can’t be an instance.
For the person who committed the action you can store their user ID as a number and the reason as a string.

The best part about using normal datastores is the fact that you can add a inf amount of tables with info inside of each other.

So you can have for example my ban script table:

local newData = {
    Player = {
        UserId = 851917460,
        Username = "DonKingFrog",
        DisplayName = "Don"
        Thumbnails = {
                Headshot = "url",
                AvatarBust = "url",
        },
    },

    BanType = "permanent",
    Reason = "No reason provided",
    Timestamp = tick(),
}

You could also use table.insert to add all warnings as a list and use a for loop to go through each warning and list it on a ScrollFrame

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.