Yes, I am developing another Admin Commands
system, but only with a better, and cleaner type of code [Different from my other ones, where they have allot of code], however, something is not executing the command, for example, when I attempt to say in the Studio, :kill player
, it will not execute the command for some reason, but, when I type in reset
, it will fire that command. Sadly, I am very confused on why it is doing this, and why it is not executing the command, I am thinking the error is at line 46
, but I am not too sure, as that is supposed to prevent someone who is not an Admin from using the :kill player
command. Here is the code I am currently using;
local Admins = { ['TheeDeathCaster'] = true; ['Player'] = true; ['yournamehere'] = true; [44391621] = true; } local Banland = { ['someoneyouhate'] = true; [40265333] = true; } local Prefixes = {":",";","/","_"} function ChkPrefix(str) local Prefix = ""; for i = 1, #Prefixes do for x = 1, #str do if str:sub(i,i) == Prefixes[i] then Prefix = str:sub(i,i) break end end end if Prefix ~= "" then return Prefix else return false end end function GetPlr(str) local plrz = {}; for i,v in pairs(game.Players:GetPlayers()) do if str ~= "" and (v.Name:lower():find(str) == (1)) then table.insert(plrz,v) end end return plrz end function Chats(plr,msg) if (msg:lower():find("reset") == (1)) then return false, plr:LoadCharacter() end if not Admins[plr.Name] and not Admins[plr.userId] and not ChkPrefix(msg) then return false end --Line 46, where I think the error is, although, this is where it is supposed to prevent a 'Non-Admin' to use the ':kill player' command local Len = ChkPrefix(msg); msg = msg:sub(Len:len()+1) --Gets the length of the 'msg' of where the 'Prefix' is, then allows you to execute the command below; if msg:lower():find("kill ") then local chk1 = msg:lower():find("kill "); local plrz = GetPlr(chk1+1); for i,v in pairs(plrz) do if v.Character then v.Character:BreakJoints() end end end end function AdminControl(plr) if Admins[plr.Name] or Admins[plr.userId] then print(plr.Name," is an Admin!") end if Banland[plr.Name] or Banland[plr.userId] then plr:Destroy() print(plr.Name," is currently banned.") end plr.Chatted:connect(function(msg) Chats(plr,msg) end) end game.Players.PlayerAdded:connect(AdminControl) for i,v in pairs(game.Players:GetPlayers()) do AdminControl(v) end
If you need me to tab my code correctly/better, I'll do it as soon as possible.
ChkPrefix
is suspicious. You don't use x
at all. Given the meaning of prefix, I would get you would want something like this:
function CheckPrefix(str) for _, prefix in pairs(Prefixes) do if str:sub(1, #prefix) == prefix then return prefix end end end
For the chunk later that uses it, I think the following would be better:
local pre = CheckPrefix(msg); if (not Admins[plr.Name] and not Admins[plr.userId]) or not pre then -- or instead of and -- `pre` instead of typing out CheckPrefix twice return false end msg = msg:sub(#pre + 1)
msg
is always used as msg:lower()
so maybe just do that at the beginning.
GetPlr
isn't given a string in the kill
command. It's given a number (chk1 + 1
) instead.