Text Displayer Not Displaying

Hello, Good Morning, Good Afternoon, Good Evening my fellow devs, I came here to ask for help on this matter.

local Interface = game.StarterGui:FindFirstChild("Interface")
local MainFrame = Interface:FindFirstChild("MainFrame")
local Category = MainFrame:FindFirstChild("Category")
local IdentificationFrame = Category:FindFirstChild("Identification")
local Background = IdentificationFrame:FindFirstChild("Background")
local Name = Background:FindFirstChild("Name")
local NameText = game.StarterGui.Interface.MainFrame.Category.Identification.Background:FindFirstChild("NameText")
local InputSymbol = Background:FindFirstChild("TextBox")
local SubmitBtn = Background:FindFirstChild("TextButton")

local elements = {
	{name = "Hydrogen", symbol = "H"},
	{name = "Helium", symbol = "He"},
	{name = "Lithium", symbol = "Li"},
	{name = "Beryllium", symbol = "Be"},
	{name = "Boron", symbol = "B"},
	{name = "Carbon", symbol = "C"},
	{name = "Nitrogen", symbol = "N"},
	{name = "Oxygen", symbol = "O"},
	{name = "Fluorine", symbol = "F"},
	{name = "Neon", symbol = "Ne"},
	{name = "Sodium", symbol = "Na"},
	{name = "Magnesium", symbol = "Mg"},
	{name = "Aluminum", symbol = "Al"},
	{name = "Silicon", symbol = "Si"},
	{name = "Phosphorus", symbol = "P"},
	{name = "Sulfur", symbol = "S"},
	{name = "Chlorine", symbol = "Cl"},
	{name = "Argon", symbol = "Ar"},
	{name = "Potassium", symbol = "K"},
	{name = "Calcium", symbol = "Ca"},
	{name = "Scandium", symbol = "Sc"},
	{name = "Titanium", symbol = "Ti"},
	{name = "Vanadium", symbol = "V"},
	{name = "Chromium", symbol = "Cr"},
	{name = "Manganese", symbol = "Mn"},
	{name = "Iron", symbol = "Fe"},
	{name = "Cobalt", symbol = "Co"},
	{name = "Nickel", symbol = "Ni"},
	{name = "Copper", symbol = "Cu"},
	{name = "Zinc", symbol = "Zn"},
	{name = "Gallium", symbol = "Ga"},
	{name = "Germanium", symbol = "Ge"},
	{name = "Arsenic", symbol = "As"},
	{name = "Selenium", symbol = "Se"},
	{name = "Bromine", symbol = "Br"},
	{name = "Krypton", symbol = "Kr"},
	{name = "Rubidium", symbol = "Rb"},
	{name = "Strontium", symbol = "Sr"},
	{name = "Yttrium", symbol = "Y"},
	{name = "Zirconium", symbol = "Zr"},
	{name = "Niobium", symbol = "Nb"},
	{name = "Molybdenum", symbol = "Mo"},
	{name = "Technetium", symbol = "Tc"},
	{name = "Ruthenium", symbol = "Ru"},
	{name = "Rhodium", symbol = "Rh"},
	{name = "Palladium", symbol = "Pd"},
	{name = "Silver", symbol = "Ag"},
	{name = "Cadmium", symbol = "Cd"},
	{name = "Indium", symbol = "In"},
	{name = "Tin", symbol = "Sn"},
	{name = "Antimony", symbol = "Sb"},
	{name = "Tellurium", symbol = "Te"},
	{name = "Iodine", symbol = "I"},
	{name = "Xenon", symbol = "Xe"},
	{name = "Cesium", symbol = "Cs"},
	{name = "Barium", symbol = "Ba"},
	{name = "Lanthanum", symbol = "La"},
	{name = "Cerium", symbol = "Ce"},
	{name = "Praseodymium", symbol = "Pr"},
	{name = "Neodymium", symbol = "Nd"},
	{name = "Promethium", symbol = "Pm"},
	{name = "Samarium", symbol = "Sm"},
	{name = "Europium", symbol = "Eu"},
	{name = "Gadolinium", symbol = "Gd"},
	{name = "Terbium", symbol = "Tb"},
	{name = "Dysprosium", symbol = "Dy"},
	{name = "Holmium", symbol = "Ho"},
	{name = "Erbium", symbol = "Er"},
	{name = "Thulium", symbol = "Tm"},
	{name = "Ytterbium", symbol = "Yb"},
	{name = "Lutetium", symbol = "Lu"},
	{name = "Hafnium", symbol = "Hf"},
	{name = "Tantalum", symbol = "Ta"},
	{name = "Tungsten", symbol = "W"},
	{name = "Rhenium", symbol = "Re"},
	{name = "Osmium", symbol = "Os"},
	{name = "Iridium", symbol = "Ir"},
	{name = "Platinum", symbol = "Pt"},
	{name = "Gold", symbol = "Au"},
	{name = "Mercury", symbol = "Hg"},
	{name = "Thallium", symbol = "Tl"},
	{name = "Lead", symbol = "Pb"},
	{name = "Bismuth", symbol = "Bi"},
	{name = "Polonium", symbol = "Po"},
	{name = "Astatine", symbol = "At"},
	{name = "Radon", symbol = "Rn"},
	{name = "Francium", symbol = "Fr"},
	{name = "Radium", symbol = "Ra"},
	{name = "Actinium", symbol = "Ac"},
	{name = "Thorium", symbol = "Th"},
	{name = "Protactinium", symbol = "Pa"},
	{name = "Uranium", symbol = "U"},
	{name = "Neptunium", symbol = "Np"},
	{name = "Plutonium", symbol = "Pu"},
	{name = "Americium", symbol = "Am"},
	{name = "Curium", symbol = "Cm"},
	{name = "Berkelium", symbol = "Bk"},
	{name = "Californium", symbol = "Cf"},
	{name = "Einsteinium", symbol = "Es"},
	{name = "Fermium", symbol = "Fm"},
	{name = "Mendelevium", symbol = "Md"},
	{name = "Nobelium", symbol = "No"},
	{name = "Lawrencium", symbol = "Lr"},
	{name = "Rutherfordium", symbol = "Rf"},
	{name = "Dubnium", symbol = "Db"},
	{name = "Seaborgium", symbol = "Sg"},
	{name = "Bohrium", symbol = "Bh"},
	{name = "Hassium", symbol = "Hs"},
	{name = "Meitnerium", symbol = "Mt"},
	{name = "Darmstadtium", symbol = "Ds"},
	{name = "Roentgenium", symbol = "Rg"},
	{name = "Copernicium", symbol = "Cn"},
	{name = "Nihonium", symbol = "Nh"},
	{name = "Flerovium", symbol = "Fl"},
	{name = "Moscovium", symbol = "Mc"},
	{name = "Livermorium", symbol = "Lv"},
	{name = "Tennessine", symbol = "Ts"},
	{name = "Oganesson", symbol = "Og"}
}

local currentElementIndex = 1

local function displayRandomElement()

	currentElementIndex = math.random(1, #elements)
	local currentElement = elements[currentElementIndex]
	NameText.Text = currentElement.name
end

local function checkAnswer(userAnswer)
	local currentElement = elements[currentElementIndex]
	if userAnswer == currentElement.symbol then
		print("Correct!")
	else
		print("Incorrect! The correct answer is " .. currentElement.symbol)
	end

	displayRandomElement()
end

SubmitBtn.MouseButton1Click:Connect(function()
	local userAnswer = InputSymbol.Text
	checkAnswer(userAnswer)
end)

displayRandomElement()

I am making a quiz game where you can choose between 2 categories, Multiple Choice, and Identification, I did the Multiple Choice very well…Until when I moved into Identification, everything does not work as expected.

The NameText which is the one who displays the full name of the element DOES NOT display the name. For the InputSymbol, idk if it works or not, I added printing but it does not print at all. So this is the time that I ask for your help.

1 Like

What type of script is this and where is it located?

It is a Lua script located at the Identification Frame itself.

Its because you are changing the text of the TextLabel which is stored inside the StarterGui folder, not the Gui that the player is holding
game.StarterGui.Interface.MainFrame.Category.Identification.Background:FindFirstChild("NameText")

StarterGui is a “folder” that holds all Guis that will be cloned and given to player on join. After being cloned is given to player which will hold their own copy of the StarterGui guis.
If your code change the Gui in StarterGui you are changing the the one that will be given to the next player that joins, not the previous players.

All these variables are wrong cause all of them are referencing that StarterGui:

local Interface = game.StarterGui:FindFirstChild("Interface")
local MainFrame = Interface:FindFirstChild("MainFrame")
local Category = MainFrame:FindFirstChild("Category")
local IdentificationFrame = Category:FindFirstChild("Identification")
local Background = IdentificationFrame:FindFirstChild("Background")
local Name = Background:FindFirstChild("Name")
local NameText = game.StarterGui.Interface.MainFrame.Category.Identification.Background:FindFirstChild("NameText")
local InputSymbol = Background:FindFirstChild("TextBox")
local SubmitBtn = Background:FindFirstChild("TextButton")

You should place the script inside the Gui, and from there create the references:

local MainFrame = script.Parent:WaitForChild("MainFrame") -- like this

local Category = MainFrame:FindFirstChild("Category")
local IdentificationFrame = Category:FindFirstChild("Identification")
local Background = IdentificationFrame:FindFirstChild("Background")
local Name = Background:FindFirstChild("Name")
local NameText = Background:FindFirstChild("NameText")
local InputSymbol = Background:FindFirstChild("TextBox")
local SubmitBtn = Background:FindFirstChild("TextButton")
1 Like

I was wondering if it was a Script or LocalScript.

A LocalScript, sorry, I didnt get you there, LocalScripts are a great fit for UI scripting.

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