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:
1 | 10 : 42 : 22.132 - ServerScriptService.AdminCmds: 16 : attempt to index nil with 'Name' |
Is Admin Func:
01 | local 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 |
10 | end |
Player Chatted Func:
01 | game.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 ) |
20 | end ) |
Thanks for the help! If you would like to see the full script, let me know (there is over 200 lines).
Hello as I know why as nil = 0 means none it should be a proper number like 1 if you're doing one command.