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

How do I make a textbox GUI that needs a certain input for something to happen?

Asked by 6 years ago

I am trying to make a username button, and I'm not sure whats wrong with my script. I don't know if I messed up the colors or not.

if
    script.Parent.Text.CaptainAlien132
    and
    MouseButton1Click:Connect(function()
script.Parent.Parent.UserEnter
then
script.Parent.Parent.UserEnter.BackgroundColor3 = "204, 255, 204"
script.Parent.Confirmed.Play()
    end     

    if
            script.Parent.Text = --Anything except my user I don't know how to do that part
    and
    MouseButton1Click:Connect(function()
script.Parent.Parent.UserEnter
then
script.Parent.Parent.UserEnter.BackgroundColor3 = "255, 89, 89"
script.Parent.Denied.Play()
wait(.2)
script.Parent.Parent.UserEnter.BackgroundColor3 = '54, 81, 81'
    end

I am a bit of a noob, so please go easy on me!

0
Hi could you explain to me what you are trying to achieve, so I can help you more clearly. Your code is confusing me a bit. Axceed_Xlr 380 — 6y
0
I want it so if my username is inputted and a button is pressed, the button plays a sound and turns pastel green. If anything but my username is inputted and pressed, it turns persimmon and the color lasts for .2 seconds and also plays a sound. Sorry if this is confusing too, I'm bad at explaining stuff.. CaptainAlien132 225 — 6y
0
I like your attempt, but your code is really confusing and has lots of errors. You’re missing some stuff, functions are in conditional statements, and the white spacing looks weird. I might completely remake your script but not now. User#20279 0 — 6y
0
Thank if you could, I wouldn't mind when it gets done because it isn't my top priority. Thanks for helping though! CaptainAlien132 225 — 6y

1 answer

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

Greetings, CaptainAlien132. I am helping you regarding the topic, "How do I make a textbox GUI that needs a certain input for something to happen?"

First of all, there are numerous mistakes in your code. Here is how to write a better codes.

1) It is better to write code inside the main function, not in an if statement.

2) Gui BackgroundColor3 takes Color3.new(value/255, value/255, value/255)

3) Indentation is required to make the code look neater.

4) Playing a sound is :Play(), not .Play()

5) Declaring variables always makes life easier. Rather than saying if code == "Name then" and so on, you could say, if code = codeValue thento make life easier.

6) not is used to check if the value is else. For ex, if text not= TextValue then

Here is the following code.

-- Declaration Section 

local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui
local enterName = playerGui.MainGui.Frame.EnterName
local goButton = playerGui.MainGui.Frame.Go
local targetMessage = "CaptainAlien132"
local debounce = false 
local confirmed = playerGui.MainGui.Frame.Confirmed -- Not too sure if this works
local denied = playerGui.MainGui.Frame.Denied -- Same as above
local confirmedColour = Color3.new(204/255, 255/255, 204/255)
local deniedColour = Color3.new(255/255, 89/255, 89/255)
local regularColour = Color3.new(54/255, 81/255, 81/255)

-- Processing Section 

local function changeNames()
    if enterName.Text == targetMessage then 
        if debounce then return end 
        debounce = true 
            enterName.BackgroundColor3 = confirmedColour
            enterName.Text = "Correct!"
            confirmed:Play()
            wait(1)
            enterName.Text = "Enter name Here"
            enterName.BackgroundColor3 = regularColour
        debounce = false 
    else
        if debounce then return end 
        debounce = true 
            for number = 0, 2, 1 do
                enterName.BackgroundColor3 = deniedColour
                wait(0.15)
                enterName.BackgroundColor3 = regularColour
                wait(0.15)
                print (number)
            end
            denied:Play()
            wait()
            enterName.BackgroundColor3 = regularColour
        debounce = false        
    end
end

-- Output Section

goButton.MouseButton1Down:Connect(changeNames)

This is the link of the Hierarchy chart if you are unsure where all the variables are

If this helped, mark it as answered. Have a lovely day of coding!
0
It didn't 100% work, but after looking through it and changing some things it worked like a charm. Thanks! CaptainAlien132 225 — 6y
0
I am glad it worked! Axceed_Xlr 380 — 6y
Ad

Answer this question