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

Why does my func give an error saying it attempted to index nil with name?

Asked by 4 years ago

I am making an admin commands script and it works. I then added in a check to make sure that the player is an admin and whenever I fire the func to check it, it returns an error:

10:42:22.132 - ServerScriptService.AdminCmds:16: attempt to index nil with 'Name'

Is Admin Func:

local function isAdmin(player)  --Checking if the requested player is an admin--
    print(player.Name)
    for _, v in pairs(admins) do    --Getting the "admins" table at line 3 and looping through it--
        print(v)
        if v == player.Name then    --If the player's name is an Admin--
            return true
        end
    end
    return false
end

Player Chatted Func:

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message,recipient)
        message = string.lower(message)
        local splitString = message:split(" ")  --Splitting up the message the player sent to see if they were typing a command or not--
        local commandPrefix = splitString[1]    --Getting the command from the message the player typed--
        local cmd = commandPrefix:split(prefix) --Getting rid of the prefix--
        local cmdName = cmd[2]  --If the player typed an actual command--
        if commands[cmdName] then   --Checking if the command is an actual command--
            local arguements = {}   --All of the things the player typed--
                if isAdmin(player) then
                for i = 2, #splitString, 1 do
                    table.insert(arguements,splitString[i])
                end
                commands[cmdName](player,arguements)    --Fire command function--
            else
                print("Not an Admin")
            end
        end
    end)
end)

Thanks for the help! If you would like to see the full script, let me know (there is over 200 lines).

1
Hello, Brody, can you give me lines 0-16 in the script "AdminCmds?" gioreyes1234 5 — 4y
0
local function isAdmin(player) --Checking if the requested player is an admin-- print(player.Name) for _, v in pairs(admins) do --Getting the "admins" table at line 3 and looping through it-- print(v) if v == player.Name then --If the player's name is an Admin-- return true end end return false end SussiestBalss 40 — 4y
0
Those are lines 15 - 24. The other lines are variables and another func (it works) SussiestBalss 40 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello as I know why as nil = 0 means none it should be a proper number like 1 if you're doing one command.

0
I don't know what you mean SussiestBalss 40 — 4y
0
Then I don't know badimo3456p 114 — 4y
0
nil (null) is a global variable that points to zero, though virtually means a non-existent value. "Attempt to index nil with", means that you're looking for a property titled Name in an invalid Object.  Ziffixture 6913 — 4y
0
I know SussiestBalss 40 — 4y
Ad

Answer this question