Chat Tag: attempt to index nil with 'Name'

  1. What do you want to achieve? I am making an inventory system that allows you to equip/unequip chat tags.

  2. What is the issue?

  3. What solutions have you tried so far? I don’t really use chat tags a lot so I don’t know how to fix this issue.

Script: StarterGui > ChatTagGui > Main > Tags > EggHunt2022 > Tag
image

script.Parent.Equip.MouseButton1Click:Connect(function(player)
	local EggHunt_2022 = {
		{
			TagText = "🐰 EGG HUNT 2022",
			TagColor = Color3.fromRGB(255, 170, 255)
		}
	}
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
	local speaker = nil
	while speaker == nil do
		speaker = ChatService:GetSpeaker(player.Name)
		if speaker ~= nil then break end
		wait(0.01)
	end	
	
	if script.Equiped.Value == true then
		local retags = {}
		speaker:SetExtraData("Tags",retags)
	else
		speaker:SetExtraData("Tags",EggHunt_2022)
	end
end)
1 Like

You’re using a server script for this; you should use a local script as it is being run from the client (startergui).
image
Instead of “player.Name” (gui.MouseButton1Click does not return any arguments), you will have to get the player’s name with the path “game.Players.LocalPlayer.Name”

Also: This line, line 12,
image
is redundant as you are checking the same condition for the while loop.

2 Likes

Now it shows this,

I may be wrong, but can’t you simply do local ChatService = game:GetService("Chat")

I could be wrong, but it’s worth a shot.

Nope

This is what I currently have in my Main LocalScript

local player = game.Players.LocalPlayer
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2125968751

script.Parent.Equip.MouseButton1Click:Connect(function()
	local EggHunt_2022 = {
		{
			TagText = "🐰 EGG HUNT 2022",
			TagColor = Color3.fromRGB(255, 170, 255)
		}
	}
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
	local speaker = nil
	while speaker == nil do
		speaker = ChatService:GetSpeaker(player.Name)
		--if speaker ~= nil then break end
		wait(0.01)
	end
	
	if script.Equiped.Value == true then
		script.Equiped.Value = false
		script.Parent.Equip.Text = "Equip"
		script.Parent.Parent.Parent.Max.Value = false
		---------------------------------
		local retags = {}
		speaker:SetExtraData("Tags",retags)
		print("✅ | Unequiped")
	else
		if script.Parent.Parent.Parent.Max.Value == false then
		    script.Equiped.Value = true
	    	script.Parent.Equip.Text = "Unequip"
			script.Parent.Parent.Parent.Max.Value = true
			---------------------------------
			speaker:SetExtraData("Tags",EggHunt_2022)
			print("✅ | Equiped")
		end	
	end
end)

while wait(1) do
	if BadgeService:UserHasBadge(player.UserId, BadgeId) then
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
	end
end
1 Like

Change script to local script and then put this code

script.Parent.Equip.MouseButton1Click:Connect(function()
	local EggHunt_2022 = {
		{
			TagText = "🐰 EGG HUNT 2022",
			TagColor = Color3.fromRGB(255, 170, 255)
		}
	}
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
	local speaker = nil
	while speaker == nil do
		speaker = ChatService:GetSpeaker(game.Players.LocalPlayer.Name)
		if speaker ~= nil then break end
		wait(0.01)
	end	
	
	if script.Equiped.Value == true then
		local retags = {}
		speaker:SetExtraData("Tags",retags)
	else
		speaker:SetExtraData("Tags",EggHunt_2022)
	end
end)

He already tried that, and got an infinite yield waiting on ServerScriptService.ChatServiceRunner:

1 Like

Ok how about use method like this

when player clicks the button by using local script , FireServer by using RemoteEvent. Then you put the chat codes stuffs inside server script. (that aerver script must be inside server script service.

2 Likes

Script: ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local EggHunt2022TAG = ReplicatedStorage:WaitForChild("EggHunt2022TAG")

local function EggHunt2022(player, Equiped)
	print(player.Name .. " fired remote event (EggHunt2022TAG)")
	
	local EggHunt_2022 = {
		{
			TagText = "🐰 EGG HUNT 2022",
			TagColor = Color3.fromRGB(255, 170, 255)
		}
	}
	local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
	local speaker = nil
	while speaker == nil do
		speaker = ChatService:GetSpeaker(player.Name)
		if speaker ~= nil then break end
		wait(0.01)
	end	

	if Equiped == true then
		local retags = {}
		speaker:SetExtraData("Tags",retags)
	else
		speaker:SetExtraData("Tags",EggHunt_2022)
	end
end

EggHunt2022TAG.OnServerEvent:Connect(EggHunt2022)

LocalScript: StarterGui

local player = game.Players.LocalPlayer
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2125968751
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("EggHunt2022TAG")

script.Parent.Equip.MouseButton1Click:Connect(function()
	if script.Equiped.Value == true then
		script.Equiped.Value = false
		script.Parent.Equip.Text = "Equip"
		script.Parent.Parent.Parent.Max.Value = false
		---------------------------------
		remoteEvent:FireServer(script.Equiped.Value)
		print("✅ | Unequiped")
	else
		if script.Parent.Parent.Parent.Max.Value == false then
		    script.Equiped.Value = true
	    	script.Parent.Equip.Text = "Unequip"
			script.Parent.Parent.Parent.Max.Value = true
			---------------------------------
			remoteEvent:FireServer(script.Equiped.Value)
			print("✅ | Equiped")
		end	
	end
end)

while wait(1) do
	if BadgeService:UserHasBadge(player.UserId, BadgeId) then
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
	end
end

Everything works but it does not give the tag and there are no errors in the console…

MouseButton1Click doesn’t return the player

That has already been established earlier in the thread.