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:

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

Is Admin Func:

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

Player Chatted Func:

01game.Players.PlayerAdded:Connect(function(player)
02    player.Chatted:Connect(function(message,recipient)
03        message = string.lower(message)
04        local splitString = message:split(" "--Splitting up the message the player sent to see if they were typing a command or not--
05        local commandPrefix = splitString[1]    --Getting the command from the message the player typed--
06        local cmd = commandPrefix:split(prefix) --Getting rid of the prefix--
07        local cmdName = cmd[2]  --If the player typed an actual command--
08        if commands[cmdName] then   --Checking if the command is an actual command--
09            local arguements = {}   --All of the things the player typed--
10                if isAdmin(player) then
11                for i = 2, #splitString, 1 do
12                    table.insert(arguements,splitString[i])
13                end
14                commands[cmdName](player,arguements)    --Fire command function--
15            else
16                print("Not an Admin")
17            end
18        end
19    end)
20end)

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