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

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

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!

4 comments

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.

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..

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.

0

Thank if you could, I wouldn't mind when it gets done because it isn't my top priority. Thanks for helping though!

1 answer

✓ Accepted answer

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.
  1. Gui BackgroundColor3 takes Color3.new(value/255, value/255, value/255)
  1. Indentation is required to make the code look neater.
  1. Playing a sound is :Play(), not .Play()
  1. 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.
  1. 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!

2 comments

0

It didn't 100% work, but after looking through it and changing some things it worked like a charm. Thanks!

0

I am glad it worked!

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