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

Why wouldn't my script change text with Table?

local TextBox = game.StarterGui.ScreenGui.TextBox

local Codes = {
	[Master] = "star"
	[Star] = "master"
}
for i,v in pairs(Codes) do
	if TextBox.Text == v then
		TextBox.Text = v
	end
end

I created a text box and if i write Master or Star in it then it should change to the strings so if i put Master then the text of the Textbox should be "star" and if i put Star then it should put "master" in the textbox text

1 comment

0

ur using starter gui not plr gui

1 answer

You have to put the code into the players GUI, becuase the GUI goes to the player after the game initialization.

Put the script parented to the text box, and this should work:

local TextBox = script.Parent -- Parent of the script.

local Codes = {
    [Master] = "star"
    [Star] = "master"
}
for i,v in pairs(Codes) do
    if TextBox.Text == v then
        TextBox.Text = v
    end
end

Later edit*

Sorry for not telling you, you have an error with the table.

You have a library, which means it's a table of variables: then you have to siignalize the variables you want to store, like [Master] and [Star] with square brackets and "", like a string.

Observe:

local TextBox = script.Parent -- Parent of the script.

local Codes = {
    ["Master"] = "star"
    ["Star"] = "master"
}
for i,v in pairs(Codes) do
    if TextBox.Text == v then
        TextBox.Text = v
    end
end

This should work as intended ;)

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