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