Banning a Player

I recently created an moderation panel and on it is a TextButton which is supposed to ban the player though it doesn’t save the ban, how would I set this up properly?

18 Likes

You could setup a ban system with datastores, which I will provide the documentation for, and the OS library (specifically time & date)

Combining this, it basically:

The ban panel adds to the datastore a table under the key of the user id, inside that table it stores the date the ban will be undone, and the reason.

Then another script checks the datastore whenever a user joins to see if they are banned / if their ban has expired.

12 Likes

You could use DataStoreService here’s an example of how to use it for banning:

local DataStoreService = game:GetService("DataStoreService") -- Get DataStoreService
local BanDataStore = DataStoreService:GetDataStore("Bans") -- Get Bans DataStore

--> Checking if the user is banned, and if so kick them
local Players = game:GetService("Players") -- Get Players Service
Players.PlayerAdded:Connect(function(Player)
    if BanDataStore:GetAsync(Player.UserId) then
          Player:Kick("Banned!")
    end --> In acutal code, please pcall GetAsync to avoid errors
end)

-- Banning a player
-- ! This assumes its in the panel, and assumes you have 'Player' defined as the target !

Player:Kick("Banned!") --> Kick the player
BanDataStore:SetAsync(Player.UserId, true) --> Set them as banned, in acutal code plese pcall SetAsync

You could instead use ModerationService which is a resource I created, currently working on a big rewrite to it after not updating it for 9 months which will fix alot of bugs it in and new features such as temporary banning

12 Likes

Where would I place this script and in what type of script? (Local or Server)

Also I need this script to execute only if the TextButton is clicked and if a text inside of an TextBox is equal to the player found inside of Players.

5 Likes

DataStoreService is only accessible by the server so you would ideally use a server script

Local Script:

  • Listen for Button Click
  • Fire RemoteEvent with the Textbox Content

Script:

  • Verify sender is an admin
  • Ban the player
8 Likes

So I insert a ServerScript inside of the TextButton and paste the sent you script above inside of it and then I make a LocalScript inside of the TextButton as well? I’m confused.

6 Likes

@CodedJer Can you explain more?

5 Likes

Upon the server loading, it will try to run server scripts, upon doing so, it should load the datastores that have the ban data inside it.

A below is the breakdown of what would happen

  1. The players clicks a button to ban a player
  2. It fires a remoteevent from the client to the server with the player is
  3. The server checks to see if the player firing the event is a proper admi, if so, step 4
  4. The server responds and adds this players id to the bandata table
  5. The server should kick the player from the game

There should also be a function that runs everytime someone joins, upon joining it will check the players id, and if it matches an id in the bandata table’s list of id’s, kick the player, effectively preventing them from joining again. You can use table.find(bantable, player.UserId) to check the player id

You could also load the new ban data table everytime someone joins just in case someone from a different server banned someone, making sure to have the most up to date ban data across servers.

5 Likes

Local script under the button and server script in script service

6 Likes

Okay thank you for your help. And I paste @CodedJer’s script into the Server Script and for the Local Script what would I add there?

4 Likes

Most of the code he provided will work, you can possible use ChatGPT to help you in creating the datastore scripts, or refer to the roblox documentation on datastores. On the client refer to the textbutton and detect a click using MouseButton1Down, connect it to a function that fires a remoteevent with the proper arguments to the server.

6 Likes

Im not to familiar with you skill level in scripting, but be advised that making a fully fleshed out moderation system is not an easy task whatsoever, there is a lot of things you have to account for, especially people trying to exploit, never NEVER, let the client determine if a player is an admin, ONLY check this on the server, it is much harder to alter data on the server.

6 Likes

Can this be exploited as it is inside of an LocalScript?

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local TextChatService = game:GetService("TextChatService")
local MainGUI = LocalPlayer.PlayerGui.Panel
local MainFrame = MainGUI.UI
local ModerationFrame = MainFrame.ModerationPanel
local PlayerFrame = MainFrame.PlayerPanel
local MenuButton = MainFrame.Menu
local ModerationButton = MainFrame.Moderation
local PlayerButton = MainFrame.Player
local WelcomeText = MainFrame.Welcome

local GroupID = 13791384
local AllowedRank = 15

TextChatService.SendingMessage:Connect(function(TextChatMessage)
	if LocalPlayer:GetRankInGroup(GroupID) < AllowedRank then
		return
	end

	local Str = TextChatMessage.Text

	if (Str == ";openpanel") then 
		MainGUI.Enabled = true 
	elseif (Str == ";closepanel") then 
		MainGUI.Enabled = false 
	end
end)
6 Likes

No, all this would really do is just open the admin panel, i would suggest before actually opening tbe panel, send an event to the server and have the server respond with a yes or no. Yes opens the panel, even though you only let admins open the panel, it should always check if the player is an admin,

I do suggest saving the gui inside of the replicated storage, as the client does not have access to it, so an exploiter wouldnt know its there, and if the player can open the panel, clone the gui and put it in their player gui

7 Likes

So I would add an script like this;

game.Players.PlayerAdded:Connect(function()
	if LocalPlayer:GetRankInGroup(GroupID) >= AllowedRank then
		local Panel = game.ReplicatedStorage.Panel:Clone()
        Panel.Parent = LocalPlayer.PlayerGui
	end

But the question is where?

6 Likes

Yes, this could commonly go into the bottom of a localscript.

Here is the documentation for remotevents

6 Likes

I added a Server Script inside of ServerScriptService and I placed the Panel inside of ReplicatedStorage and used this script;

local Players = game.Players
local ReplicatedStorage = game.ReplicatedStorage

local GroupID = 13791384
local AllowedRank = 15

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(GroupID) >= AllowedRank then
		local Panel = ReplicatedStorage.Panel:Clone()
		Panel.Parent = Player.PlayerGui
	end
end)

And it worked, it clones the GUI to the Player’s GUI upon joining the game if they are at Rank 15 or Above.

5 Likes

Is this everything you needed?

6 Likes

Well I guess, it didn’t fully help me but thank you for your help.

5 Likes

The best thing i can suggest is reading rhe roblox documentation and maybe youtube videos to learn how it all works

7 Likes