How can I toggle a players chat tag on/off

Hi! Thanks for stopping by. :slight_smile: I want to know if there is a method to turn off a players chat tag ( some thing like: [Mod][wayIxn]: Hello world!

I’m trying to use a command like ‘/tog’ to toggle the chat tag, but I have found no way to update it in-game. :frowning:

Here’s my chat tag code:

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local Speaker = ChatService:GetSpeaker(PlayerName)
		if (Players[PlayerName].Stats.IsMod.Value == true and (Players[PlayerName].TempStats.ShowTag.Value == true)) then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
		Speaker:SetExtraData('Tags', {{TagText = '🚨Mod', TagColor = Color3.fromRGB(255, 52, 52)}})
	end
end)
1 Like

Try this to toggle the tags off

Speaker:SetExtraData('Tags', nil)

1 Like

From which script? I need the Admin Command to say something as of “/tog” to toggle it, then the chat tags script to toggle it off. (I think.)

Oh I thought you were only asking how to toggle the tags off. If you want to make admin commands, you may want to read this article.

I’m not experienced with making admin commands :no_mouth:

1 Like

haha, I;ve got the command set up, just a simple server script when a player says /tog it will fire. But would I have to put it in the command function?

My command script:

local prefix = '/'
local admins = {'wayIxn', 'W0Qk'}

local bans = {}

--// Functions
local function ban(plr)
	table.insert(bans, plr)
	plr:Kick('You have been banned from this server.')
	print(plr.Name..' has been temporarily banned.')
end

local function kick(plr)
	plr:Kick('You have been kicked from this server by an administrator.')
	print(plr.Name..' has been kicked from the server.')
end

local function pban(plr)
	plr.Stats.IsPbanned.Value = true
	plr:Kick('You have been permanently banned from this game.')
	print(plr.Name..' has been permanently banned from the game.')
end

local togTag = true
local function showTag(plr)
	if togTag == true then
		togTag = false
		plr.TempStats.ShowTag.Value = false
	else
		togTag = true
		plr.TempStats.ShowTag.Value = true
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:connect(function(msg)
		for i = 1, #admins do
			if plr.Name == admins[i] then
				if msg:sub(1,5):lower() == prefix..'ban ' then
					for _,v in pairs(game.Players:GetChildren()) do
						if v:FindFirstChild('PlayerGui') and v.Name:lower():match(msg:sub(6):lower()) then
							ban(v)
						end
					end
					elseif msg:sub(1,6):lower() == prefix..'pban ' then
					for _,v in pairs(game.Players:GetChildren()) do
						if v:FindFirstChild('PlayerGui') and v.Name:lower():match(msg:sub(7):lower()) then
							pban(v)
						end
					end
					elseif msg:sub(1,6):lower() == prefix..'kick ' then
					for _,v in pairs(game.Players:GetChildren()) do
						if v:FindFirstChild('PlayerGui') and v.Name:lower():match(msg:sub(7):lower()) then
							kick(v)
						end
					end
				elseif msg:sub(1,4):lower() == prefix..'tog' then
					togTag(plr)
				end
			end
		end
	end)
end)

I think instead of using this

local function showTag(plr)
	if togTag == true then
		togTag = false
		plr.TempStats.ShowTag.Value = false
	else
		togTag = true
		plr.TempStats.ShowTag.Value = true
	end
end

you should straight away use the tags code

	if togTag == true then
		togTag = false
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
	    Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
	    Speaker:SetExtraData('Tags', nil)
	else
		togTag = true
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
	    Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
	    Speaker:SetExtraData('Tags', {{TagText = '🚨Mod', TagColor = Color3.fromRGB(255, 52, 52)}})
	end
end

I’ll try doing something to this extent. Thanks for the early reply! :slight_smile:

1 Like

Nope… couldn’t get it to work ;( Thank you for trying and I’ll just keep experimenting. :smiley:

1 Like

Update:

I got this line to work:

if (Players[PlayerName].Stats.IsMod.Value == true and

I set it to false on join, and when I set it to true it shows, but How would I do it w/o SpeakerAdded? I’ve tried a loop and Obviously it didn’t work…

When IsMod.Value is true, I think you can skip to this code

local Speaker = ChatService:GetSpeaker(PlayerName)
Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
Speaker:SetExtraData('Tags', {{TagText = '🚨Mod', TagColor = Color3.fromRGB(255, 52, 52)}})

if (Players[PlayerName].Stats.IsMod.Value == true then
   local Speaker = ChatService:GetSpeaker(PlayerName)
   Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
   Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
   Speaker:SetExtraData('Tags', {{TagText = '🚨Mod', TagColor = Color3.fromRGB(255, 52, 52)}})
end
1 Like

Should I put it into a loop?

Actually, How would I get ‘PlayerName’?

Whenever a player says /tog, do you pass the player name to the function?

Yes. local function toggleTag(plr)
end)

To lessen the passing of variables, I think you should insert this in your admin script

elseif msg:sub(1,4):lower() == prefix..'tog' then
	if (Players[plr.Name].Stats.IsMod.Value == false then
      Players[plr.Name].Stats.IsMod.Value = true
      local Speaker = ChatService:GetSpeaker(plr.Name)
      Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 52, 52))
      Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 130, 130))
      Speaker:SetExtraData('Tags', {{TagText = '🚨Mod', TagColor = Color3.fromRGB(255, 52, 52)}})
   else
      --some code to remove the tags
   end
end

but the mods would have to say /tog whenever they join the game

1 Like

Unfortunately, I’m stuck and just can’t do this. I may figure it out eventually, thanks for your time and effort. :slight_smile: I really appreciate it.

1 Like