Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Is my admin not working (x2)?

Asked by
IcyEvil 260 Moderation Voter
9 years ago

Here is the error

Workspace.Script:3: bad argument #1 to 'pairs' (table expected, got nil)

and script below

admins = {"amegaman"}

for i,v in pairs(isAdmin) do
    for x,c in pairs(admins) do
        if c and v == true then
            return true
        elseif c.Chatted and true then
            c.Chatted = true return
        end
    end
end

function message()
    if msg:sub(1,4) == "msg " then
        vic = msg:sub(1,9)
        m = Instance.new("Message")
        m.Parent = game.Workspace
        m.Text = (vic.Name.." "..Chatted)
    end
end
1
You are attempting to call 'isAdmin' which does not exist in the script, and line 15 would be 'vic = msg:sub(5)'. TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

You didn't define what isAdmin is in line 3. It's expecting a table, but you don't have one set for that. You shouldn't even need that line as well as line 11.

Ad
Log in to vote
0
Answered by 9 years ago

Here, I remade your script, I've been working on Admin Scripts for along time now, I'll also explain the coding;

local isAdmin = {} --This is where the Names of Players will be stored 'Will be Admins'

local function ChkAdmin(plr,str) --This will be used to check if a Player is an Admin or not (Player's Name, if admin)
for i = 1, #isAdmin do --This gets all the strings within isAdmin
if plr:lower() == isAdmin[i]:lower() then --If the Player's name is in the isAdmin list then
return true --It'll return true
end --This ends the code for the 'if' statement
end --This ends the code for the 'for' loop
return false --It'll return false if not
end --This ends the code for the 'function'

local function GetPlr(plr,str) --We'll use this to get the Player
for i,v in pairs(game.Players:GetPlayers()) do --This gets all the players that are currently in 'game.Players'
if v.Name:lower():find(plr:lower()) then --If the script found a Player matching what the Player said then
return v --It'll return v
end --This ends the code for the 'if' statement
end --This ends the code for the 'for' loop
end --This ends the code for the 'function'

local function onChat(msg,plr) --Now, this'll be used for the Commands

if not ChkAdmin(plr.Name,false) then return end --If the Player is not an Admin, then it'll return the Player false, elseif Player is one, it'll allow the player to use the command(s) below

if msg:lower():sub(1,4) == "msg " then --If the commands starts with  'msg ' then
local plrz = GetPlr(msg:sub(5),false) --This will get the Player's name
if plrz then --If the Player exists then
m = Instance.new("Message") --This will create a new message
m.Parent = game.Workspace --This set the Message's parent to 'game.Workspace'
m.Text = plr.Name.." is in game" --The text will say that the Player is in the game
wait(#msg:sub(5)) --Will wait 'Amount of character', for Instance, 'print("Hi")' is 11 characters
if m ~= nil then --If the Message still exists
m:Destroy() --The message will be destroyed
end --This ends the code for the first 'if' statement
end --This ends the code for the second 'if' statement
end --This ends the code for the third 'if' statement

end --This ends the code for the 'function'

local function AdminControl(plr) --Another new function, used to admin the Player
plr.Chatted:connect(function(msg) --This will fire everytime the Player's chats something
onChat(msg,plr) --This connects the Player's Chat to the commands
end) --This ends the code for if '.Chatted' event
end --This ends the code for the 'function

game.Players.PlayerAdded:connect(AdminControl) --This connects AdminControl to the Player when the Player joins the server
for i,v in pairs(game.Players:GetPlayers()) do AdminControl(v) end --As a just-in-case if the 'PlayerAdded' event wasn't after enough, or if you add a AutoUpdate feature

I hope this helped!

Answer this question