CODE REVIEW - Admin Commands

So I recently just started admin commands few minutes ago, I’m not sure if theres and better way to handle the administrators & the banned players and the commands list.

I’m also getting errors on the Command list so im make a post on that.

--/// Command List Info \\--
local title = "Basic Admin"


local titlebutton = script.Parent.TitleCard.TitleClose
titlebutton.MouseButton1Click:Connect(function()
	script.Parent.Parent.Cmds.Visible=false
end)
script.Parent.TitleCard.TitleLabel.Text = title


--/// General Admin Programming \\--

-- Administration In Admin
local AdminList = {"im_sams","ToxicCooling"}
local BanList = {"Noob","Noob2"}
local BanReason = "You have been banned"
local BanAppeal = " | Appeal Appeal at are group wall why should be un-banned"
local IsAdmin = false
local IsBanned = false
-- IsAdmin()
game.Players.PlayerAdded:connect(function(player)
for _, v in pairs(AdminList) do
if player.Name == v then
IsAdmin = true
print("RS ADMIN | IsAdmin() = true")
else
IsAdmin = false
print("RS ADMIN | IsAdmin() = false")
end
end
end)
-- IsBanned()
game.Players.PlayerAdded:connect(function(player)
for _, v in pairs(BanList) do
if player.Name == v then
	player:Kick(BanReason,BanAppeal)
IsBanned = true
print("RS ADMIN | IsBanned() = true")
else
IsBanned = false
print("RS ADMIN | IsBanned() = false")
end
end
end)

-- Command Configuration
--[[
REMOVED DUE TO WELL FOR REAL BUD THIS LIKE THE MAIN THING 
OF THE COMMANDS.  This is all coding of :heal me, :Kick player, :cmds,etc removed
from script due to this is coding review and I know for fact this works
and I don't like people who copy me. or people who copys peoples stuff and
don't do and work at all.



]]






--/// Command List \\--


--//Kick
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "Kick".." -"
Command.Desc.Text = "Kick and player from the server"
Command.Visible=true
--//Cmds
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "Cmds".." -"
Command.Desc.Text = "Opens this gui what your currently viewing"
Command.Visible=true
--//Music
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "Music".." -"
Command.Desc.Text = "Play music in the server"
--//Prefix
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "Prefix".." -"
Command.Desc.Text = "Figure out the Admin commands prefix"
Command.Visible=true

--//Place
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "Place".." -"
Command.Desc.Text = "Teleport players in the server to and game"
Command.Visible=true
--//Announce
local Command = script.Parent.CommandList.CommandExample:Clone()
Command.Name = "Command"
Command.Title.Text = "msg".." -"
Command.Desc.Text = "Broadcast and message across the server"
Command.Visible=true
1 Like

So first and foremost, try to make your code a little cleaner by indenting properly. It goes a long way and makes it easier to read. Next, is this a localscript or a serverscript? Judging by the UI input events it appears to be local, its just a little confusing to look at. Next to that you really never should have to call an event like PlayerAdded twice, that just gives the computer extra unneeded work to do. Have it check for bans, if they are banned then kick them and kill the code. If they arent banned then check if they are admin. If they are an admin then give them the privileges you want to give them. For more organized code you should utilize functions aswell. For example an IsBanned function, an Is Admin function for simple checks. Lastly, work on splitting things up between the server and client. Have the server do all the checks for bans and admins. Then have the server tell the client what it can do using remotes. You also should be using different variables at the bottom for you “CommandExamples” rather than copying and pasting and changing the UI properties. If you have any more questions feel free to PM or reply here.

5 Likes

Based on the code, i’d saying work on just the general spacing and indentations.

I put a space in between every line of code, and on parameters a space after every comma.

It helps to read everything easier, and, in all just more efficient (for my eyes, hehe).

But, everyone has a different scripting style.

Also, I prefer using User-Id rather than Usernames, BUT, you can actually use both. Just check if v is a string or a number and go from there.

1 Like

Considering using OOP for each command , since it seems that’s what you’re going for anyways.

Also your comments are pretty misleading, they’re telling me that one of your PlayerAdded events are a function called “IsBanned”, but that’s simply not true.

Only other problems I see are just nitpicks.

1 Like

[update] this coding is old view new post. Admin Commands - Code Review - #2 by Autterfly