Chat tag script not working

Hi devs,

I have a command that our moderators can use to disguise themselves as a normal player with a certain rank, but it doesn’t seem to be working.

Script: (client sided)

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local chatWindowConfiguration = textChatService.ChatWindowConfiguration

local bindable = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("DisguiseMod")

local function getPlayerName(player: Player)
	return player.Name
end

local Tags = {
	[255] = {"<font color='#d54e50'><b>[Owner]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[9] = {"<font color='#d54e50'><b>[Manager]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[8] = {"<font color='#bc49ff'><b>[Developer]</b></font>", "<font color='#bc49ff'>%s:</font>"},
	[7] = {"<font color='#00c3ff'><b>[Admin]</b></font>", "<font color='#00c3ff'>%s:</font>"},
	[6] = {"<font color='#ff8902'><b>[Moderator]</b></font>", "<font color='#ff8902'>%s:</font>"},
	[5] = {"<font color='#ff77ed'><b>[Translator]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[4] = {"<font color='#ff77ed'><b>[Contributor]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[3] = {"<font color='#a7ff34'><b>[Friend]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[2] = {"<font color='#a7ff34'><b>[Partner]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[1] = {"<font color='#a7ff34'><b>[Gang]</b></font>", "<font color='#a7ff34'>%s:</font>"}
}

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = getPlayerName(player)
			local rankInGroup = player:GetRankInGroup(8423759)

			if Tags[rankInGroup] then
				local prefix = Tags[rankInGroup][1]
				local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			end

		end
	end

	return properties
end

bindable.OnClientEvent:Connect(function(executor, toggle, rank)
    local playerName = getPlayerName(executor)
    print("Executor Name:", playerName)
    print("Toggle:", toggle)
    print("Rank:", rank)
    
    local properties = Instance.new("TextChatMessageProperties")

    if toggle then
        if rank == "Guest" then
            properties.PrefixText = string.format("%s:", playerName)
            print("Rank set to Guest.")
        elseif rank == "Gang" then
            if Tags[1] then
                local prefix = Tags[1][1]
                local formattedMessage = string.format(Tags[1][2], playerName)
                properties.PrefixText = prefix .. " " .. formattedMessage
                print("Rank set to Gang.")
            end
        elseif rank == "Partner" then
            if Tags[2] then
                local prefix = Tags[2][1]
                local formattedMessage = string.format(Tags[2][2], playerName)
                properties.PrefixText = prefix .. " " .. formattedMessage
                print("Rank set to Partner.")
            end
        elseif rank == "Friend" then
            if Tags[3] then
                local prefix = Tags[3][1]
                local formattedMessage = string.format(Tags[3][2], playerName)
                properties.PrefixText = prefix .. " " .. formattedMessage
                print("Rank set to Friend.")
            end
        end
    else
        if rank == nil then
            local rankInGroup = executor:GetRankInGroup(8423759)
            print("Rank in Group:", rankInGroup)
            if Tags[rankInGroup] then
                local prefix = Tags[rankInGroup][1]
                local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
                properties.PrefixText = prefix .. " " .. formattedMessage
                print("Reverted to original rank.")
            end
        end
    end
    
    print("Properties:", properties.PrefixText)
end)

Output: (toggled on with the rank “Gang”)

  16:59:06.484  Executor Name: TeamDreams123 -  Client - ChatTags:49
  16:59:06.484  Toggle: true  -  Client - ChatTags:50
  16:59:06.484  Rank: Gang  -  Client - ChatTags:51
  16:59:06.484  Rank set to Gang.  -  Client - ChatTags:64
  16:59:06.484  Properties: <font color='#a7ff34'><b>[Gang]</b></font> <font color='#a7ff34'>TeamDreams123:</font>  -  Client - ChatTags:94

Please help.

My general advice is to put print statements throughout the code and see where it stops running where you want it to.

I can look into a bit more in a bit.

2 Likes

Ok, so after reading the code through and trying to implement it myself with my own group, I see that nothing is connecting the code from the RemoteEvent Function and the textChatService.OnIncomingMessage . That’s the short answer. How to connect the two bits of code, there are many ways to do so.


spoofAsMemeber_DevForumThing.rbxl (61.7 KB)


You could have a value inside the LocalScript itself and simply update that based on the remote event, instead of what’s currently happening, but that’s prone to Members/Gang, and other ranks other than mods, spoofing on Members/Gang? Which doesn’t actually matter now that I write than out I think.

I was going to call this implementation complicated, but then my own implementation (BoolValue on Player when added into game and doing more of the checking on the Server) also complicated things unnecessarily. The video and file I have above has a simple solution, but it works from my testing.

Note that I also got rid of some ranks I didn’t have in my own group, so that it would work. You’d have to add those back, but I hope that helps!

1 Like

Alright, so I merged them 2 scripts together, here is my outputting script:

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent_DisguiseMod = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("DisguiseMod")

local groupId = 12315422
local modRank = 255

local playerIsSpoofing = false

local Tags = {
	[255] = {"<font color='#d54e50'><b>[Owner]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[9] = {"<font color='#d54e50'><b>[Manager]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[8] = {"<font color='#bc49ff'><b>[Developer]</b></font>", "<font color='#bc49ff'>%s:</font>"},
	[7] = {"<font color='#00c3ff'><b>[Admin]</b></font>", "<font color='#00c3ff'>%s:</font>"},
	[6] = {"<font color='#ff8902'><b>[Moderator]</b></font>", "<font color='#ff8902'>%s:</font>"},
	[5] = {"<font color='#ff77ed'><b>[Translator]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[4] = {"<font color='#ff77ed'><b>[Contributor]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[3] = {"<font color='#a7ff34'><b>[Friend]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[2] = {"<font color='#a7ff34'><b>[Partner]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[1] = {"<font color='#a7ff34'><b>[Gang]</b></font>", "<font color='#a7ff34'>%s:</font>"}
}

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = player.Name
			local rankInGroup = player:GetRankInGroup(groupId)
			print(rankInGroup)

			if not playerIsSpoofing then
				if Tags[rankInGroup] then
					local prefix = Tags[rankInGroup][1]
					local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
					properties.PrefixText = prefix .. " " .. formattedMessage
					print("formatted..")
				else
					warn("Rank not in Tags List")
				end
			else
				if rankInGroup == modRank then
					if Tags[1] then
						local prefix = Tags[1][1]
						local formattedMessage = string.format(Tags[1][2], playerName)
						properties.PrefixText = prefix .. " " .. formattedMessage
						print("spoofing as Member rank.")
					end
				end
			end
		end
	end

	return properties
end

remoteEvent_DisguiseMod.OnClientEvent:Connect(function(executor_toSend, isDisguiseModEnabled)
	if players.LocalPlayer == executor_toSend then
		print(players.LocalPlayer, executor_toSend)
		playerIsSpoofing = isDisguiseModEnabled
	end
end)

remoteEvent_DisguiseMod.OnClientEvent:Connect(function(executor, toggle, rank)
	local playerName = executor.Name
	print("Executor Name:", playerName)
	print("Toggle:", toggle)
	print("Rank:", rank)

	local properties = Instance.new("TextChatMessageProperties")

	if toggle then
		if rank == "Guest" then
			properties.PrefixText = string.format("%s:", playerName)
			print("Rank set to Guest.")
		elseif rank == "Gang" then
			if Tags[1] then
				local prefix = Tags[1][1]
				local formattedMessage = string.format(Tags[1][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Gang.")
			end
		elseif rank == "Partner" then
			if Tags[2] then
				local prefix = Tags[2][1]
				local formattedMessage = string.format(Tags[2][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Partner.")
			end
		elseif rank == "Friend" then
			if Tags[3] then
				local prefix = Tags[3][1]
				local formattedMessage = string.format(Tags[3][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Friend.")
			end
		end
	else
		if not rank then
			local rankInGroup = executor:GetRankInGroup(8423759)
			print("Rank in Group:", rankInGroup)
			if Tags[rankInGroup] then
				local prefix = Tags[rankInGroup][1]
				local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Reverted to original rank.")
			end
		end
	end

	print("Properties:", properties.PrefixText)
end)

There is a warn though.

  19:17:41.668  0  -  Client - ChatTags:32
  19:17:41.668  Rank not in Tags List  -  Client - ChatTags:41

And I see that you added that warn into the code, but I do not know why it won’t work.

Any idea?

Snippet of code where the warn is coming from:

if not playerIsSpoofing then
				if Tags[rankInGroup] then
					local prefix = Tags[rankInGroup][1]
					local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
					properties.PrefixText = prefix .. " " .. formattedMessage
					print("formatted..")
				else
					warn("Rank not in Tags List") -- warn
				end
			else
				if rankInGroup == modRank then
					if Tags[1] then
						local prefix = Tags[1][1]
						local formattedMessage = string.format(Tags[1][2], playerName)
						properties.PrefixText = prefix .. " " .. formattedMessage
						print("spoofing as Member rank.")
					end
				end
			end

Switch the GroupID variable with your GroupID. The code still has my groupid, which you’re not in, so the code passed a 0 for a Guest/not in the groupid.

You should also probably add a [0] = " " to the Tags list for Guest ranks so players who aren’t in the group also have chat formatted similarly.

Hope that makes sense!

1 Like
local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent_DisguiseMod = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("DisguiseMod")

local groupId = 8423759
local modRank = 6

local playerIsSpoofing = false

local Tags = {
	[255] = {"<font color='#d54e50'><b>[Owner]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[9] = {"<font color='#d54e50'><b>[Manager]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[8] = {"<font color='#bc49ff'><b>[Developer]</b></font>", "<font color='#bc49ff'>%s:</font>"},
	[7] = {"<font color='#00c3ff'><b>[Admin]</b></font>", "<font color='#00c3ff'>%s:</font>"},
	[6] = {"<font color='#ff8902'><b>[Moderator]</b></font>", "<font color='#ff8902'>%s:</font>"},
	[5] = {"<font color='#ff77ed'><b>[Translator]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[4] = {"<font color='#ff77ed'><b>[Contributor]</b></font>", "<font color='#ff77ed'>%s:</font>"},
	[3] = {"<font color='#a7ff34'><b>[Friend]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[2] = {"<font color='#a7ff34'><b>[Partner]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[1] = {"<font color='#a7ff34'><b>[Gang]</b></font>", "<font color='#a7ff34'>%s:</font>"},
	[0] = {" "}
}

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = player.Name
			local rankInGroup = player:GetRankInGroup(groupId)
			print(rankInGroup)

			if not playerIsSpoofing then
				if Tags[rankInGroup] then
					local prefix = Tags[rankInGroup][1]
					local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
					properties.PrefixText = prefix .. " " .. formattedMessage
					print("formatted..")
				else
					warn("Rank not in Tags List")
				end
			else
				if rankInGroup == modRank then
					if Tags[1] then
						local prefix = Tags[1][1]
						local formattedMessage = string.format(Tags[1][2], playerName)
						properties.PrefixText = prefix .. " " .. formattedMessage
						print("spoofing as Member rank.")
					end
				end
			end
		end
	end

	return properties
end

remoteEvent_DisguiseMod.OnClientEvent:Connect(function(executor_toSend, isDisguiseModEnabled)
	if players.LocalPlayer == executor_toSend then
		print(players.LocalPlayer, executor_toSend)
		playerIsSpoofing = isDisguiseModEnabled
	end
end)

remoteEvent_DisguiseMod.OnClientEvent:Connect(function(executor, toggle, rank)
	local playerName = executor.Name
	print("Executor Name:", playerName)
	print("Toggle:", toggle)
	print("Rank:", rank)

	local properties = Instance.new("TextChatMessageProperties")

	if toggle then
		if rank == "Guest" then
			properties.PrefixText = string.format("%s:", playerName)
			print("Rank set to Guest.")
		elseif rank == "Gang" then
			if Tags[1] then
				local prefix = Tags[1][1]
				local formattedMessage = string.format(Tags[1][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Gang.")
			end
		elseif rank == "Partner" then
			if Tags[2] then
				local prefix = Tags[2][1]
				local formattedMessage = string.format(Tags[2][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Partner.")
			end
		elseif rank == "Friend" then
			if Tags[3] then
				local prefix = Tags[3][1]
				local formattedMessage = string.format(Tags[3][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Friend.")
			end
		end
	else
		if not rank then
			local rankInGroup = executor:GetRankInGroup(8423759)
			print("Rank in Group:", rankInGroup)
			if Tags[rankInGroup] then
				local prefix = Tags[rankInGroup][1]
				local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Reverted to original rank.")
			end
		end
	end

	print("Properties:", properties.PrefixText)
end)

This works, but even if I set it to “Gang” then it will not display the gang rank.

It will just remove all chat prefixes

I’m confused what “it” means in this context. I assume you mean you are trying to spoof being the Gang rank, but I could be wrong. I don’t have any of this code in my version at all, so I’d assume something there would be the issue:

remoteEvent_DisguiseMod.OnClientEvent:Connect(function(executor, toggle, rank)
	local playerName = executor.Name
	print("Executor Name:", playerName)
	print("Toggle:", toggle)
	print("Rank:", rank)

	local properties = Instance.new("TextChatMessageProperties")

	if toggle then
		if rank == "Guest" then
			properties.PrefixText = string.format("%s:", playerName)
			print("Rank set to Guest.")
		elseif rank == "Gang" then
			if Tags[1] then
				local prefix = Tags[1][1]
				local formattedMessage = string.format(Tags[1][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Gang.")
			end
		elseif rank == "Partner" then
			if Tags[2] then
				local prefix = Tags[2][1]
				local formattedMessage = string.format(Tags[2][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Partner.")
			end
		elseif rank == "Friend" then
			if Tags[3] then
				local prefix = Tags[3][1]
				local formattedMessage = string.format(Tags[3][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Rank set to Friend.")
			end
		end
	else
		if not rank then
			local rankInGroup = executor:GetRankInGroup(8423759)
			print("Rank in Group:", rankInGroup)
			if Tags[rankInGroup] then
				local prefix = Tags[rankInGroup][1]
				local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
				print("Reverted to original rank.")
			end
		end
	end

	print("Properties:", properties.PrefixText)
end)

I do see local prefix set everywhere where you mention the Gang rank. Try Printing prefix and see if that’s blank.

I assume though that the issue again is different parts of the script not communicating with one another. Specifically when we change the properties of an IncomingMessage. We have to change the properties in that function, not after, so the other remoteEvent_DisguiseMod.OnClientEvent you have isn’t actually changing the messages that are incoming. It’s changing something, but not what it needs to cause it can’t in that scope. Or, I think that’s what’s happening.

1 Like

Sorry for being vague, I mean the “rank” variable in the function was set to “Gang”

Line 82: print(prefix)

Output:

  21:09:03.413  <font color='#a7ff34'><b>[Gang]</b></font>  -  Client - ChatTags:82

Still need help on this. @Reditect

I checked the difference between our two scripts here: DevForum - Chat Tag Not Work Compare - Diffchecker. Not much matters until line 67.

It looks like you want to make it so the mods can choose what rank they spoof as, instead of it only being locked to the Gang rank. Is this correct?


Edit:

If so, here’s an updated version:
spoofAsMemeber_DevForumThing.rbxl (65.2 KB)

Note that the rank spoofing input is only sent when enabling the spoofer through the UI button I made. It’s not sent when disabling. This means if you have a rank spoof enabled already, disable it, input a new number, and then rank number (0-255), and then Enable the spoof by clicking the button again.

I could’ve done a submit button or tried to do stuff based on InputChanged, but each has a drawback.

There is an option between Guest, Gang, Friend and Partner.

(Guest is ment to have no chat tag, and just the player’s default chat name colour)

I’ll provide the script that fires the remote event to see if you need to edit that:

-- Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local logMessageEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("SendLog")

local bindable = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Other"):WaitForChild("DisguiseMod")
local disguised = false

return function(context, rank)
	local executor = context.Executor
	local currentTime = os.date("%X", os.time())
	local boldmessage = string.format("[%s] @%s:", currentTime, executor.Name)

	local message
	if disguised then
		bindable:FireAllClients(executor, false, nil)
		disguised = false
		message = "undisguised."
		context:Reply("Undisguised. Redo this command to return back to disguise mode.")
	else
		bindable:FireAllClients(executor, true, rank)
		disguised = true
		message = string.format("disguised. Disguised as rank: %s.", rank)
		context:Reply(("Disguised to rank %s. Redo this command to return to normal."):format(rank))
	end

	local formattedText = string.format("<font color='#FFFFFF'><b>%s</b> %s</font>", boldmessage, message)
	logMessageEvent:FireAllClients(formattedText)

	return ("")
end