Issue with Chat Tags

I’m having this error and not sure how to fix it.

Script:

function module.ChatTag(player, button, frame)
	local Players = game:GetService("Players")
	local tcs = game:GetService("TextChatService")
	local rs = game:GetService("ReplicatedStorage")
	
	local tags_module = require(rs.Game.Modules.Server.tags_module)
	
	local on = false
	local tagClicked = false

	button.Activated:Connect(function()
		on = not on
		if on then
			button.Image = "rbxassetid://113287267199779"
			frame.Visible = true
		else
			button.Image = "rbxassetid://86158734518876"
			frame.Visible = false
		end
	end)
		
	local function SetupTags()
		for _, tag in tags_module.Tags do
			if tag then
				if player:IsInGroup(tag.Group) and player:GetRankInGroup(tag.Group) >= tag.Rank and not frame.TagHolder:FindFirstChild(tag.Name) then
					local button = frame.TagHolder.Template:Clone()
					button.Name = tag.Name
					button.TextLabel.Text = tag.Name
					button.TextLabel.TextColor3 = Color3.fromHex(tag.Color)
					button.Visible = true
					button.Parent = frame.TagHolder
				end
			end
				
		for _, CustomTag in tags_module.Custom do
				if CustomTag then
					if player.UserId == CustomTag.ID and not frame.TagHolder:FindFirstChild(CustomTag.Name) then
						local CustomButton = frame.TagHolder.Template:Clone()
						CustomButton.Name = CustomTag.Name
						CustomButton.TextLabel.Text = CustomTag.Name
						CustomButton.TextLabel.TextColor3 = Color3.fromHex(CustomTag.Color)
						CustomButton.Visible = true
						CustomButton.Parent = frame.TagHolder
					end
				end
			end
		end
	end
	
	local function OnTagClick(button)
		for _, tag in tags_module.Tags do
			if tag then
				tcs.OnIncomingMessage = function(message : TextChatMessage)
					if not message.TextSource then
						return
					end

					local properties = Instance.new("TextChatMessageProperties")
					local playerByID = Players:GetPlayerByUserId(message.TextSource.UserId)
					properties.PrefixText = "<font color='"..tags_module.Tags[button.Name].Color.."'>"..tags_module.Tags[button.Name].Tag.."</font> "..message.PrefixText 
					return properties
				end
			end
		end
					
		for _, tag in tags_module.Custom do
			if tag then	
				tcs.OnIncomingMessage = function(message : TextChatMessage)
					if not message.TextSource then
						return
					end

					local properties = Instance.new("TextChatMessageProperties")
					local playerByID = Players:GetPlayerByUserId(message.TextSource.UserId)
					properties.PrefixText = "<font color='"..tags_module.Custom[button.Name].Color.."'>"..tags_module.Custom[button.Name].Tag.."</font> "..message.PrefixText 
					return properties
				end
			end
		end	
	end

	SetupTags()
	
	for _, button in frame.TagHolder:GetChildren() do
		if button:IsA("ImageButton") or button:IsA("TextButton") then
			button.Activated:Connect(function()
				print("clicked")
				tagClicked = not tagClicked
				OnTagClick(button)
			end)
		end
	end
	
	frame.RemoveTags.Activated:Connect(function()
		tcs.OnIncomingMessage = function(message : TextChatMessage)
			if not message.TextSource then
				return
			end
		end
	end)
end

Would you be able to send the code on line 183?

properties.PrefixText = "<font color='"..tags_module.Custom[button.Name].Color.."'>"..tags_module.Custom[button.Name].Tag.."</font> "..message.PrefixText 

Read the error carefully, it tells you exactly what is wrong.

tags_module.Custom[button.Name].Color

Whatever string button.Name is intended to be is coming up as nil under tags_module.Custom. I would do a quick debug test by adding a print right before this line to see what button.Name is actually coming up as, then you can double check tags_Custom and make sure it exists; then, make sure the button has the correct name or that the button you intend to be indexing is the correct object.

The thing is the button does have the correct name. Whenever I click the custom one it turns on, yet when I click a different one as I have others under tags_module.Tags it doesn’t work even though it has the correct name and index is correct.

If you aren’t using print to debug this, it will be very difficult to prove whether or not an undesired button name is passing through this function.

In any case, if there is any chance that the children of tags haven’t loaded, you made need to use WaitForChild in this case so it isn’t indexed before it exists.

I find it more likely that an undesired button name is passing through the function, you should eliminate that concern by printing it and testing.

I did print it, I can try using a WaitForChild to see if that will fix it.

WaitForChild sadly didn’t work. Button name is still correct so not too sure what is wrong.

Can you provide a screenshot of the prints and of the related objects in the explorer?

I found out, thank you for your time.

1 Like

No problem. Glad I could help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.