So I'm writing a system for my moderators to be able to easily view bans and then reason, date of ban and etc..
Here's my current script
local DataStoreService = game:GetService("DataStoreService"):GetDataStore("PlayerInfo") game.Players.PlayerAdded:connect(function(plr) local key -- where I'm having issues local moderation = Instance.new("Folder", plr) moderation.Name = "Moderation" local baninfo = Instance.new("BoolValue", moderation) baninfo.Name = "Banned" local DOB = Instance.new("StringValue", moderation) DOB.Name = "DateOfBan" local BB = Instance.new("StringValue", moderation) BB.Name = "BannedBy" local UI = Instance.new("StringValue", moderation) UI.Name = "UserId" UI.Value = plr.userId local nam = Instance.new("StringValue", moderation) nam.Name = "Username" local RS = Instance.new("StringValue", moderation) RS.Name = "Reason" local getSaved = DataStoreService:GetAsync(key) if getSaved then baninfo = getSaved[1] else local NumbersForSaving = {baninfo.Value} DataStoreService:SetAsync(key, NumbersForSaving) end end) game.Players.PlayerRemoving:connect(function(plr) local key -- also where I'm having issues local saveTable = {plr.moderation.Banned.Value} DataStoreService:SetAsync(key, saveTable) end)
what I want is to be able to use a key and then all the banned players names come up and then open up their name and see reason, date of ban, bannedby, and userId
I'm using Crazyman32's DataStore Editor as a way of viewing of the DataStore if that helps
So if I understand correctly, you simply want to store a table of bans into a datastore containing information about why they were banned, who they were banned by, date they were banned etc.
I would use something along the lines of:
local Datastore = game:GetService("DataStoreService"):GetDataStore("PlayerInfo") local Banlist = {} --A table which we will use to store our data local Key = "Banlist" --A generic key which we will store all of our data under game.Players.PlayerAdded:connect(function(Player) --Will fire when player joins Banlist = Datastore:GetAsync(Key) --Will update the list every time someone joins for _,Bans in pairs(Banlist) do --Loop through the banlist if (Bans['userId'] == Player.userId) then --If they are already banned then... Player:Kick("You are banned from the server") --Kick the player return --Stop the function from continuing end end local moderation = Instance.new("Folder", Player) --You know this part... moderation.Name = "Moderation" local baninfo = Instance.new("BoolValue", moderation) --Are they banned? baninfo.Name = "Banned" local DOB = Instance.new("StringValue", moderation) --When were they banned? DOB.Name = "DateOfBan" local BB = Instance.new("StringValue", moderation) --Who banned them? BB.Name = "BannedBy" local UI = Instance.new("StringValue", moderation) --Guy who banned them's userId UI.Name = "UserId" local RS = Instance.new("StringValue", moderation) --Reason for ban? RS.Name = "Reason" end) game.Players.PlayerRemoving:connect(function(Player) --Will fire when the player leaves if (Player.Moderation.Banned.Value) then --If they were banned local Moderation = Player.Moderation Datastore:UpdateAsync(Key, function(Bans) --Update the datastore ("Bans" is the list already stored) table.insert(Bans, { ['userId'] = Player.userId; ['DateOfBan'] = Moderation.DateOfBan.Value; ['BannedBy'] = Moderation.BannedBy.Value; ['BannerUserId'] = Moderation.UserId.Value; ['Reason'] = Moderation.Reason.Value; }) --Add the ban to the banlist return Bans --Update the list end) end end)
There are better ways of doing this, but I don't have much time. If you have questions, please drop a PM or comment.
If you want help with the datastores, or techniques which I have used here, check my answer on this question.
This script only handles the saving of the data, if you want to ban/unban them then you will need to write separate code