Text label inside of bilboard gui not clearing old text when ".Text" is given new text

  1. What do you want to achieve?
    I have a billboard GUI with a textlabel named “PlayerName” using PlayerAdded, and CharacterAdded events a function clones this GUI from replicated storage parents it to the players head, and then fills the “.Text” with the player’s name. In a seperate script I have a function that fires a remote call to change the “.Text” field with user-inputted text from a TextBox in a menu GUI. I want the behaviour to be that the initial player name that is placed into “.Text” is replaced with the user-inputted text from the TextBox in the GUI.

  2. What is the issue?
    Right now the TextLabel is retaining the initial player name overlaying the user inputted text. Upon changing the user inputted text it properly updates, YET retains the overlaying player name text which is not proper behavior! In a sense it’s “doubled” the text label.

  3. What solutions have you tried so far?
    Cloning a bilboard gui from a freemodel script that was working properly (incase there were weird settings I had selected inside of my billboard gui)
    Disabling Scripts and Screen Gui
    Commenting out line 15 on the “BillboardGuiName” Server Script.
    (This gives me the behavior I want with the TextBox, but does not start the player off with their username, which is something I want)

Below is BillboardGuiName Script

--##Services##
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--local chatService = game:GetService("Chat")
--##Variables##
local NameChangeEvent = game.ReplicatedStorage.NameChange


--##Functions##
--Below needs to be rewritten to work with NameChangeEvent connect
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
		local clonedobject = ReplicatedStorage.BillboardGui:Clone()
		clonedobject.Parent = workspace:WaitForChild(player.Name).Head
		workspace:FindFirstChild(player.Name).Head:WaitForChild("BillboardGui").PlayerName.Text = player.Name
    end)
end)

function NameChange(player, text)
	local name
	
	local suc,err = pcall(function ()
		local filtered = game:GetService("Chat"):FilterStringForBroadcast(text, player)
		print (filtered)
        workspace:FindFirstChild(player.Name).Head:WaitForChild("BillboardGui").PlayerName.Text = filtered
	end)
	if not suc then
		name = "Filtering error: "..err..", please try again."
	end
end

NameChangeEvent.OnServerEvent:Connect(NameChange)

--TODO Max character limit that makes sense with bilboard gui/ text input size.

Below is local script that goes into GUI

--##SERVICES##
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--##VARIABLES##
local acceptUserInput = true;
local player = game.Players.LocalPlayer
local gui = player.PlayerGui.ScreenGui.ClassMenuFrame
local roleplaybox = gui.RolePlayBox
local NameChangeEvent = game.ReplicatedStorage.NameChange
local mouse = player:GetMouse()
--local name

--##FUNCTIONS##
UserInputService.TextBoxFocused:connect(
    function()
        acceptUserInput = false;
    end
)
UserInputService.TextBoxFocusReleased:connect(
    function()
        acceptUserInput = true;
    end
)
UserInputService.InputEnded:connect(function( inputObject, gameProcessedEvent )
    if (gameProcessedEvent) then
        return
    end
    if (acceptUserInput) and (inputObject.UserInputType == Enum.UserInputType.Keyboard and inputObject.KeyCode == Enum.KeyCode.T) then
        -- open/close GUI
		gui.Visible = not gui.Visible
    end
end)

roleplaybox.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		print("Focus was lost because enter was pressed!")
		local name = roleplaybox.Text
		NameChangeEvent:FireServer(name)
	end
end)

Billboard gui is located in ReplicatedStorage
and Remote Events are located in ReplicatedStorage

2 Likes

Did you check and see what elements exist inside of the BillboardGui when this doubling occurs? Like, is a new TextLabel made?

3 Likes

Yes I did, no new elements are created there is still only 1 TextLabel named PlayerName in the Billboard GUI that is located in the player’s head. (I should mention I have another TextLabel named “ClassName” within this Billboard GUI, but no script is interacting with it)
In the below image this was done using my name change gui.

*Also, this doubling still occurs even if I change the text manually while playing in studio, and when I delete that PlayerName TextLabel after adding text live in studio it only deletes the player username that is displayed but my newly added text sticks around.

1 Like

If you delete the whole BillboardGui does the text persist?

1 Like

Yes,

2 Likes

So it’d appear that you have another BillboardGui with the adornee being the player’s head, the question would be to figure out where that’s being created from/stored.

4 Likes

Figuring this out is going to be a pain, just to be safe I created a new place and copied over only relevant scripts/screengui… same behavior… so it’s got to be something in the scripts.

2 Likes

Commenting out lines 13-15 on “BillboardGuiName Script” keeps ANY Billboard Gui from being created, so something weird must be happening there?

1 Like

How many times does your CharacterAdded event fire/run?

Btw instead of this:

workspace:WaitForChild(player.Name).Head

You could just do:

char:FindFirstChild("Head") or  char:WaitForChild("Head")
1 Like

Going to be out for a moment, I’m still relatively inexperienced… would throwing a print statement in here in the event connected function give me an idea?

1 Like

You can search while ingame “billboardgui”, as Roblox allows you to search for an instance’s type. This’d help you find the duplicate.

2 Likes

You may only have one BillboardGui as a child of the avatar’s Head part, but do you have a BillboardGui anywhere else that has the Adornee set to a part of the character?

Do you have a place file (rbxl) that reproduces the problem? I can’t repro with your code examples, it works as expected for me. Posting a repro place might help figure out if it’s a duplicate gui or a rendering issue.

2 Likes

I found the duplicate one guys… I have a viewport frame that displays the character and it was duplicating the Billboard GUI, thanks I’ve been going crazy over this.

1 Like