Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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).

3 comments

1

Hello, Brody, can you give me lines 0-16 in the script "AdminCmds?"

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

0

Those are lines 15 - 24. The other lines are variables and another func (it works)

1 answer

✓ Accepted answer

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

4 comments

0

I don't know what you mean

0

Then I don't know

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. 

0

I know

This discussion is preserved as it was. New answers, comments, and votes are closed.