Attempt to index nil with `PlayerId`

Hi. I am using this chat tag module and when I test the script, I get the error "Attempt to index nil with PlayerId

The script:

for i,v in pairs(EDM.Players) do
		if v['PlayerId'] == nil then
			if player.UserId == v['PlayerId'] then
				if v['Tag'] ~= nil then
					table.insert(tags, v['Tag'])
				end
				if v['ChatColor'] ~= nil then
					if chatColor == nil then
						chatColor = v['ChatColor']
					end
				end
				if v['NameColor'] ~= nil then
					if nameColor == nil then
						nameColor = v['NameColor']
					end
				end
				if v['Rainbow'] ~= nil then		
					rainbowChat = true
				
				end
			end
		end
	end

The module:

Players = 
		{
			{

				PlayerId = 208100335, -- p1xnet
				Tag = {TagText = "DEVELOPER", TagColor = Color3.fromRGB(255, 0, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			PlayerId = 902603595, -- thespecialnone
			Tag = {TagText = "DEVELOPER", TagColor = Color3.fromRGB(255, 0, 0)},
			NameColor = Color3.fromRGB(255, 0, 0),
			ChatColor = Color3.fromRGB(255,255,255),
			Rainbow = true,

			{

				PlayerId = 1026849565, -- b4_stackz
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 275151861, -- spider
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 1863625746, -- jail
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 1411828672, -- rebathing
				Tag = {TagText = "MODERATOR", TagColor = Color3.fromRGB(255, 114, 168)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(0, 76, 255),

			},


		},
if v['PlayerId'] ~= nil then
1 Like

I have tried that already, same error occurred.

Which line does it reference to? Can you quote it?

1 Like
ServerScriptService.ChatCustomization:22: attempt to index number with 'PlayerId'  -  Server - ChatCustomization:22
  13:54:13.478  Stack Begin  -  Studio
  13:54:13.478  Script 'ServerScriptService.ChatCustomization', Line 22 - function setExtraData  -  Studio - ChatCustomization:22
  13:54:13.478  Script 'ServerScriptService.ChatCustomization', Line 168

also here is the module i am using: Chat tags and other chat modifications module (Without forking the chat) + Rainbow Chat

What is EDM exactly? Do you really need to mention that in the for loop? Why not just put Players in the for loop?

Edit: Nvm. I thought all of the code was in the module, didn’t realize that the first given code was in a server script.

Also, i found a little mistake in the Players table, you forgot to add another pair of squiggly brackets for one of the players.

Fixed code

Players = 
		{
			{

				PlayerId = 208100335, -- p1xnet
				Tag = {TagText = "DEVELOPER", TagColor = Color3.fromRGB(255, 0, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{
				PlayerId = 902603595, -- thespecialnone
				Tag = {TagText = "DEVELOPER", TagColor = Color3.fromRGB(255, 0, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 1026849565, -- b4_stackz
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 275151861, -- spider
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 1863625746, -- jail
				Tag = {TagText = "ADMIN", TagColor = Color3.fromRGB(34, 255, 0)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(255,255,255),
				Rainbow = true,
			},

			{

				PlayerId = 1411828672, -- rebathing
				Tag = {TagText = "MODERATOR", TagColor = Color3.fromRGB(255, 114, 168)},
				NameColor = Color3.fromRGB(255, 0, 0),
				ChatColor = Color3.fromRGB(0, 76, 255),

			},


		}

EDM is the module.
local EDM = require(script.ExtraDataModule)

Also now I get the error: “Attempt to index nil with gamepassid”

Is it the same mistake I did before?

Gamepass = 
		{
			GamepassId = 24824565, -- vip gamepass
			Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 255, 0)},
			NameColor = Color3.fromRGB(255, 255, 0),
			ChatColor = Color3.fromRGB(255, 255, 0),
			Rainbow = true,

			{
				GamepassId = 24824070, -- small donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},

			{
				GamepassId = 24739477, -- med donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},

			{
				GamepassId = 24824184, -- large donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},


		};

Oh, I did. I just needed an extra bracket.

Gamepass = 
		{
{
			GamepassId = 24824565, -- vip gamepass
			Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 255, 0)},
			NameColor = Color3.fromRGB(255, 255, 0),
			ChatColor = Color3.fromRGB(255, 255, 0),
			Rainbow = true,

			{
				GamepassId = 24824070, -- small donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},

			{
				GamepassId = 24739477, -- med donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},

			{
				GamepassId = 24824184, -- large donor
				Tag = {TagText = "VIP", TagColor = Color3.fromRGB(255, 62, 65)},
				NameColor = Color3.fromRGB(255, 255, 0),
				ChatColor = Color3.fromRGB(255, 0, 0),


			},


		};
};

Thanks for your help, have a great day!

1 Like

Ah, okay. Glad your issue has been fixed. Happy to help!