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

How do I make it if a player puts a certain text in a text box it makes a text label visible?

Asked by 3 years ago

Code:

local textBox = script.Parent

local secretWord = "Testing1"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green

textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Write the text here"
textBox.BackgroundColor3 = colorNormal

local function onFocused()
    textBox.BackgroundColor3 = colorNormal
end

local function onFocusLost(enterPressed, inputObject)
    if enterPressed then
        local guess = textBox.Text
        if guess == secretWord then
            script.Parent.Parent.TextLabel.Visible = false
if script.Parent.Text == "Testing1" then
script.Parent.Parent.TextLabel.Visible = true
else
print("Test")
end
            textBox.Text = "TestRight"
            textBox.BackgroundColor3 = colorCorrect
        else
            textBox.Text = "TestWrong"
            textBox.BackgroundColor3 = colorWrong
        end
    else
        textBox.Text = ""
        textBox.BackgroundColor3 = colorNormal
    end
end

textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

How the gui is placed: https://i.gyazo.com/b69941e3a9e752aa47b71c2a0c65e874.png

0
Any errors? ThatDevTim 188 — 3y
0
14:17:16.461 - TextLabel is not a valid member of Frame 14:17:16.463 - Stack Begin 14:17:16.465 - Script 'Players.DevSeveral.PlayerGui.ScreenGui.Frame.Chatbox.LocalScript', Line 23 - function onFocusLost 14:17:16.466 - Stack End DevSeveral 19 — 3y

1 answer

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

Your error is in line 24, like the error message says. You are doing 1 too many ".parent"s. ".Parent" Goes to the TextBox, and another ".Parent" goes to the frame.

New Code Line 24

script.Parent.TextLabel.Visible = true

All Code

local textBox = script.Parent

local secretWord = "Testing1"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green

textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Write the text here"
textBox.BackgroundColor3 = colorNormal

local function onFocused()
    textBox.BackgroundColor3 = colorNormal
end

local function onFocusLost(enterPressed, inputObject)
    if enterPressed then
        local guess = textBox.Text
        if guess == secretWord then
            script.Parent.TextLabel.Visible = false
if script.Parent.Text == "Testing1" then
script.Parent.TextLabel.Visible = true
else
print("Test")
end
            textBox.Text = "TestRight"
            textBox.BackgroundColor3 = colorCorrect
        else
            textBox.Text = "TestWrong"
            textBox.BackgroundColor3 = colorWrong
        end
    else
        textBox.Text = ""
        textBox.BackgroundColor3 = colorNormal
    end
end

textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)
0
There was some confusion so I added the full code. ThatDevTim 188 — 3y
Ad

Answer this question