Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Toggling Chat Tags script not working. How do I fix it?

I'm trying to make a chat tag toggling system so for example, when I say "/tog" it turns the chat tag on/off depending if it is already on or off. There was no error, it's in server script service. Please help.

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

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

ChatService.SpeakerAdded:Connect(function(PlayerName, plr)
	local Speaker = ChatService:GetSpeaker(PlayerName)
	if (Players[PlayerName].UserId == game.CreatorId) then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(255, 0, 0)}})
		plr.Chatted:Connect(function(msg)
			if string.sub(msg,1,4) == "/tog" then
				local Value = Instance.new("BoolValue")
				if Value.Value == true then
					Value.Value = false
					if Value.Value == false then
						if (Players[PlayerName].UserId == game.CreatorId) then
							Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 134, 136))
							Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 134, 136))
							Speaker:SetExtraData('Tags', nil)
						else
							Value.Value = true
							if Value.Value == true then
								Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
								Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
								Speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(255, 0, 0)}})
							end
						end
					end
				end
			end
		end)
	end
end)

3 comments

0

.SpeakerAdded only returns speaker name

0

Your script didnt work

0

What's the problem? Did it print any errors? I tested my script and it's all working...

1 answer

✓ Accepted answer

game:GetService("ChatService").SpeakerAdded parameter only returns speakerName

So you want to modify your script a little bit. Also your script is a little bit messy from line 14. Also you are creating new BoolValue everytime player.Chatted event ran causing the value will always be false.

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

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

ChatService.SpeakerAdded:Connect(function(speakerName)
	local Speaker = ChatService:GetSpeaker(speakerName)
	if (Players[speakerName].UserId == game.CreatorId) then
		local Value = Instance.new("BoolValue")
		Value.Parent = Players[speakerName]

		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(255, 0, 0)}})

		Players[speakerName].Chatted:Connect(function(msg)
			if string.sub(msg,1,4) == "/tog" then
				if Players[speakerName].UserId == game.CreatorId then
					if Value.Value == true then
						Value.Value = false
						Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
						Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
						Speaker:SetExtraData('Tags', {{TagText = 'Owner', TagColor = Color3.fromRGB(255, 0, 0)}})
					else
						Value.Value = true
						Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 134, 136))
						Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 134, 136))
						Speaker:SetExtraData('Tags', nil)
					end
				end
			end
		end)
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.