Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wouldn't my script change text with Table?

Asked by 3 years ago
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

0
ur using starter gui not plr gui greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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 ;)

Ad

Answer this question