Kick/Ban GUI issues

Hello, guys. I’m trying to make a kick/ban GUI, but I’m having a couple of issues.

Number 1 - I want to make the kick GUI accessible by people on a list on a script, but when I tried to do so, the GUI failed to work.

In the script, I added this table to the kick script - local admins = {‘MichaelLaurent’} and made some slight changes on that script to try to make it only usable by people on that table. However, as I tried to test the GUI on myself, it didn’t do anything, so I require assistance in order for it to work correctly.

Number 2 - I don’t know how to make a ban system that keeps a player banned when the player’s name and reason is entered and a button is pressed. I believe that it’s something to do with table.insert scripts. If possible, I could also gain some assistance in making a temporary ban script, where you enter the length of the ban in the GUI when you ban a player.

I have attached a file of the current kick script, plus what the GUI looks like. If anyone could help me with my issue, please do. Thank you so much.!

Screenshot_32

1 Like

Before I break this down, you can add codes to your posts using the grave accent key (``) next to the 1 key on your keyboard; it would show like this: local variable. In case you want to make a multi-line script, you can add three grave accents at the beginning, and then add the programming language after, like “lua”. And once you finish it, you add three of the grave accents key at the end of the script.

Now, to answer your first question: To loop through stuff in a table, you can accomplish that by what I will do in the following code:

local Admins = {"Player1", "Player2"} -- I prefer using UserIds, in case if the player changes their username, but it's up to you.
local Player = game.Players.LocalPlayer
local IsAdmin = false

for _, admin in pairs(Admins) do
	if Player.Name == admin then
		IsAdmin = true
	end
end
print(Player.Name ..": ".. IsAdmin) -- If the player is an admin (their name is listed in the table), it will print "Player1: true", otherwise it will print "Player1: false".

And as for the second question: I’m not really sure, I usually just make it local (ban players in 1 server), or use datastore. You can use APIs like Trello and other services.
You can check the Trello API page, I’m not that good with HttpService.

Okay, thanks so much for helping with the first question. For the second question, I’m not really familiar with Trello and other APIs, which means I might need to play around a little. Referring back to the first question, if I were to place that code in the kick script, where exactly should I put it to make it function correctly? Or do I have to make a separate script?

P.S. If necessary, I’ll just have the permanent ban thing plus an unban script, that’ll work for me too.

It’s up to you. You can have it in a ModuleScript inside ReplicatedStorage, and then require it whenever you want to access the table.

For me, I have a ModuleScript, called like “Admins”, in ReplicatedStorage, and require it whenever I want to access the table from the server, or the client. It’s honestly much better, and easier for accessing later. And it will make it easier to be accessed from different scripts, rather than copying the same table and pasting them in each script you want to access the table. But as I said, it’s up to you.

That does sound interesting. However, I don’t really know how to set up a ban script using things like ModuleScripts and ReplicatedStorage. If you can, could you please explain to me how it would work and what the basic scripting would look like? Thanks a bunch.

I am sort of new to advanced scripting, which is why I joined this forum in the hopes that I’d be able to share my attempts.

I did make a local banning/unbanning script before using my admin commands, it’s messy, as I was experimenting on them. Basically, I stored like command names in a table in a ModuleScript inside a server-side script, with a function, and the player argument, and I had a ModuleScript called “Bans” in ReplicatedStorage, and whenever an admin says like /ban Player1, or let’s say, if they’re lazy: /ban playe, it will fire the function stored in the table, and I have another function to get the player easily, even if it’s incomplete. Like if an admin typed playe, it will search for all players that start, or have playe in their names, capitalization doesn’t matter, and if there are at least two or more with the same name, it completely ignores the command, but if it found a player, it will return their full name, so like Player1. So, when the admin says the command, and it gets the player and everything, it starts to add their username (I should’ve made it UserIds instead) to a table in the ModuleScript called “Bans”, as I mentioned above, and in that ModuleScript (to easily access and check banned players), I have a function that can be fired to check all players in the table, and see if the supplied player argument matches any of them, if it does, it will return true, otherwise false.

I know you’re probably confused, so here are both of ModuleScripts.
(There are also remote events and stuff like that for chat messages and blah blah. The “Bans” ModuleScript is located exactly in ReplicatedStorage.ModuleScripts.Format, just fyi)

-- "AdminCommands" ModuleScript, stored inside a server-side script (in ServerScriptService, to be exact).

-- The function that gets the player's full name.
function GetPlayer(Player)
	for _, p in pairs(game.Players:GetPlayers()) do
		if p:IsA("Player") and string.match(string.lower(p.Name), string.lower(Player)) then
			return p
		end
	end
end

-- The commands table.
local module = {
	ban = function(Player)
		if Player == nil then return end
		if not GetPlayer(Player) then -- Player isn't in the server.
			for i = 1, #Bans do
				if not string.match(string.lower(Player), string.lower(Bans[i])) then
					table.insert(Bans, Player)
					game.ReplicatedStorage.RemoteEvents.Client.ServerMessage:FireAllClients("Server", Player .." has been banned!", Color3.fromRGB(255, 0, 0))
					break
				end
			end
			return
		end
		Player = GetPlayer(Player)
		if Admins.IsAdmin(Player) then return end
		table.insert(Bans, Player.Name)
		game.ReplicatedStorage.RemoteEvents.Client.ServerMessage:FireAllClients("Server", Player.Name .." has been banned!", Color3.fromRGB(255, 0, 0))
		Player:Kick(Settings.BanMessage)
	end,
	unban = function(Player)
		if Player == nil then return end
		if #Bans <= 0 then return end -- No banned players.
		if not GetPlayer(Player) then -- Player isn't in the server.
			for i = 1, #Bans do
				if string.match(string.lower(Player), string.lower(Bans[i])) then
					game.ReplicatedStorage.RemoteEvents.Client.ServerMessage:FireAllClients("Server", Bans[i] .." has been unbanned!", Color3.fromRGB(0, 255, 127))
					table.remove(Bans, i)
					break
				end
			end
			return
		end
		Player = GetPlayer(Player)
		if Admins.IsAdmin(Player) then return end
		for i = 1, #Bans do
			if Bans[i] == Player.Name then
				game.ReplicatedStorage.RemoteEvents.Client.ServerMessage:FireAllClients("Server", Bans[i] .." has been unbanned!", Color3.fromRGB(0, 255, 127))
				table.remove(Bans, i)
				break
			end
		end
	end
}
-- "Bans" ModuleScript, stored in ReplicatedStorage.

local Bans = {
	"SomeoneThatIHate"
}

function Bans.IsBanned(Player)
	if type(Player) == "userdata" then Player = Player.Name end -- If the "Player" argument was the player object, get their name.
	for _, ban in pairs(Bans) do
		if type(Player) == "string" and type(ban) == "string" then
			if string.lower(Player) == string.lower(ban) then
				return true
			end
		end
	end
	return false
end

return Bans
5 Likes

I was a bit confused over the explanation, but when I was looking at the script you posted, I realized what you were talking about. I’ll definitely post that script or something very similar in my GUI, but I still have a few more problems I want to rectify:

  • The unban system (although with my previous knowledge of scripting, I could slightly modify the script but it might break)
  • The reasons for the ban/kick. It is typable on the GUI, but if the moderator/administrator doesn’t want to supply a reason, they could have an option not to do so, and that means modifying the script
  • Additional moderation commands (for example, mute and server message)

I’m so glad that you’ve helped me with this. I’ll continue thinking of some scripts to add into the GUI as you reply.

1 Like

The script I posted was just for my admin commands. You’re free to use it, modify it, or do anything you like. I’m more than happy to help.

I just noticed something. I don’t exactly know how to change the script so it’s used from a GUI as I posted rather than saying it in the chat. Could you possibly help with that?

Add me on discord, I’ll help you with that. It would take ages writing them down here lol.
Scri🅿tily#6808

1 Like