(TextChatService) Scripts aren't detecting bubbles properly

Title says it all.

There’s no errors in the output though. It is split up into 2 scripts, server and client.

Server:

local NameTag = Instance.new("BillboardGui")
NameTag.Name = "NameTag"
NameTag.Size = UDim2.new(4, 0, 1, 0)
NameTag.StudsOffset = Vector3.new(0, 2.5, 0)
NameTag.AlwaysOnTop = true

local Frame = Instance.new("Frame", NameTag)
Frame.Size = UDim2.new(1, 0, 1, 0)
Frame.BackgroundTransparency = 1

local ImageLabel = Instance.new("ImageLabel", Frame)
ImageLabel.Size = UDim2.new(0.1, 0, 0.35, 0)
ImageLabel.Position = UDim2.new(0.45, 0, 0, 0)
ImageLabel.BackgroundTransparency = 1
ImageLabel.Visible = false

local TopText = Instance.new("TextLabel", Frame)
TopText.Name = "TopText"
TopText.Size = UDim2.new(0.7, 0, 0.3, 0)
TopText.Position = UDim2.new(0.15, 0, 0.35, 0)
TopText.BackgroundTransparency = 1
TopText.TextScaled = true
TopText.TextColor3 = Color3.new(1, 1, 1)
TopText.Font = Enum.Font.GothamBold

local ClanText = Instance.new("TextLabel", Frame)
ClanText.Name = "ClanText"
ClanText.Size = UDim2.new(1, 0, 0.3, 0)
ClanText.Position = UDim2.new(0, 0, 0.7, 0)
ClanText.BackgroundTransparency = 1
ClanText.TextScaled = true
ClanText.TextColor3 = Color3.new(1, 1, 1)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local head = character:WaitForChild("Head")
		local clone = NameTag:Clone()
		clone.Parent = head

		local topText = clone.Frame.TopText
		local clanText = clone.Frame.ClanText
		local imageLabel = clone.Frame.ImageLabel

		topText.Text = "@" .. player.Name

		local data = player:WaitForChild("Data")
		local clansFolder = data:WaitForChild("ClansFolder")

		local function updateClanValues()
			local clanNameValue = clansFolder:FindFirstChild("ClanName")
			local clanColorValue = clansFolder:FindFirstChild("ClanColor")
			local clanRankValue = clansFolder:FindFirstChild("ClanRank")

			local clanName = "No Clan"
			local clanColor = Color3.new(1, 1, 1)
			local rank = ""

			if clanNameValue and clanNameValue.Value ~= "" then
				clanName = clanNameValue.Value
				clanColor = clanColorValue and clanColorValue.Value or Color3.new(1, 1, 1)
				clanText.TextColor3 = clanColor
				rank = clanRankValue and clanRankValue.Value or ""
				clanText.Text = clanName .. "'s " .. rank
			else
				clanText.Text = clanName
			end
		end

		task.spawn(function()
			while true do
				updateClanValues()
				local disguisedValue = player:WaitForChild("Data"):WaitForChild("Disguised")
				local groupId = 8423759
				local playerRank = player:GetRankInGroup(groupId)

				if disguisedValue.Value then
					imageLabel.Visible = false
				else
					if playerRank >= 6 then
						imageLabel.Image = "rbxassetid://88965800154544"
						imageLabel.Visible = true
					else
						imageLabel.Visible = false
					end
				end

				task.wait(0.1)
			end
		end)
	end)
end)

Client script:

local TweenService = game:GetService("TweenService")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local activeBubbles = 0

local function fadeGui(guiObject, targetTransparency, duration)
	local tween = TweenService:Create(
		guiObject,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{BackgroundTransparency = targetTransparency}
	)
	tween:Play()
end

local function fadeText(guiObject, targetTransparency, duration)
	local tween = TweenService:Create(
		guiObject,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{TextTransparency = targetTransparency}
	)
	tween:Play()
end

local function fadeModeratorIcon(imageLabel, targetTransparency, duration)
	local tween = TweenService:Create(
		imageLabel,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{ImageTransparency = targetTransparency}
	)
	tween:Play()
end

local function updateNameTagVisibility()
	local nameTag = character:FindFirstChild("NameTag")
	if nameTag then
		local frame = nameTag:FindFirstChild("Frame")
		local topText = frame and frame:FindFirstChild("TopText")
		local clanText = frame and frame:FindFirstChild("ClanText")
		local imageLabel = frame and frame:FindFirstChild("ImageLabel")

		local targetTransparency = activeBubbles > 0 and 1 or 0

		if frame then fadeGui(frame, targetTransparency, 0.5) end
		if topText then fadeText(topText, targetTransparency, 0.5) end
		if clanText then fadeText(clanText, targetTransparency, 0.5) end
		if imageLabel then fadeModeratorIcon(imageLabel, targetTransparency, 0.5) end
	end
end

TextChatService.OnBubbleAdded = function(textChatMessage)
	if textChatMessage and textChatMessage.TextSource then
		local sourcePlayer = Players:GetPlayerByUserId(textChatMessage.TextSource.UserId)
		if sourcePlayer == player then
			activeBubbles += 1
			updateNameTagVisibility()
		end
	end
end

Thanks for your help!

(please don’t send documentation links, I’ve already gone through them all)

2 Likes

Still need help on this.

1 Like

Can you explain more? (Sorry :doh:)

local TweenService = game:GetService("TweenService")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local activeBubbles = 0

local function fadeGui(guiObject, targetTransparency, duration)
	local tween = TweenService:Create(
		guiObject,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{BackgroundTransparency = targetTransparency}
	)
	tween:Play()
end

local function fadeText(guiObject, targetTransparency, duration)
	local tween = TweenService:Create(
		guiObject,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{TextTransparency = targetTransparency}
	)
	tween:Play()
end

local function fadeModeratorIcon(imageLabel, targetTransparency, duration)
	local tween = TweenService:Create(
		imageLabel,
		TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
		{ImageTransparency = targetTransparency}
	)
	tween:Play()
end

local function updateNameTagVisibility()
	local nameTag = character:FindFirstChild("NameTag")
	if nameTag then
		local frame = nameTag:FindFirstChild("Frame")
		local topText = frame and frame:FindFirstChild("TopText")
		local clanText = frame and frame:FindFirstChild("ClanText")
		local imageLabel = frame and frame:FindFirstChild("ImageLabel")

		local targetTransparency = activeBubbles > 0 and 1 or 0

		if frame then fadeGui(frame, targetTransparency, 0.5) end
		if topText then fadeText(topText, targetTransparency, 0.5) end
		if clanText then fadeText(clanText, targetTransparency, 0.5) end
		if imageLabel then fadeModeratorIcon(imageLabel, targetTransparency, 0.5) end
	end
end

TextChatService.OnBubbleAdded = function(textChatMessage: TextChatMessage)
	if textChatMessage and textChatMessage.TextSource then
		local sourcePlayer = game.Players:GetPlayerByUserId(textChatMessage.TextSource.UserId)
		if sourcePlayer == player then
			task.spawn(function()
				activeBubbles += 1
				updateNameTagVisibility()
				task.wait(TextChatService.BubbleChatConfiguration.BubbleDuration)
				activeBubbles -= 1
				updateNameTagVisibility()
			end)
		end
	end
end

Would this work?

1 Like

I managed to fix it because it wasn’t referring to “Head” instead, it referred to the “Character”

Thanks!

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