Bank GUI Not Working

I currently have the following UI:
image

The task that I am trying to accomplish is turning the Enter Password textbox red upon a wrong entry and green upon the correct password.

The following code is what I currently have:

local textBox = script.Parent
local object = script.Parent.Parent
object.AnchorPoint = Vector2.new(0.5, 0.5)
object.Position = UDim2.new(0.1, 0, 0.5, 0)
local function onFocusLost(enterPressed)
	if enterPressed then
		print("The player typed: " .. textBox.Text)
		if textBox.Text == "1234" then
			textBox.BackgroundColor3 = Color3.new(0, 1, 0.498039)
		end
	else if enterPressed then
			if textBox.Text ~= "1234" then
			textBox.BackgroundColor3 = Color3.new(1, 0, 0)
			object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))
			end
	end
end
textBox.FocusLost:Connect(onFocusLost)

As you can tell I was also trying to add some tweening to it, for example when it’s wrong I want it to have that shake effect. Though my current priority is making sure that the UI is red when wrong and green when right!

If anyone can help that would be great thanks!

2 Likes

Is there any errors ?
Also could you be a bit more descriptive i don’t think i understand the issue

I really want to help you but can you add more description so we can understand what is the problem and what you need to obtain.
Thank you !

Your original code’s else if enterPressed then line’s if statement will never be true, because if enterPressed is true, then the code in the first if enterPressed statement will be run, although only the print is done if the password is wrong.

local function onFocusLost(enterPressed)
	if enterPressed then
		print("The player typed: " .. textBox.Text)
		if textBox.Text == "1234" then
			textBox.BackgroundColor3 = Color3.new(0, 1, 0.498039)
		else
			textBox.BackgroundColor3 = Color3.new(1, 0, 0)
			object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))
		end
	end
end

Ya so I mean it is really simple and this goes for @starnova224 as well, all I want to do is have it so that when I type in a password if it is correct when I click enter then the UI textbox turns green, otherwise it turns red.

I just added that I was working on making it shake when it turns red as an effect to explain why I am tweening :slight_smile:

After testing this in studio @RoBoPoJu has the solution
That is if you are trying to make the background of the Textbox change color

Hello! This is a bit off-topic, I’m sorry but you should probably make it say “Bank account : enter code” so it looks less like a scam. This is just to make roblox think it isn’t a scam thing. Have a good day.

1 Like

To address your concern, this system is not for public or in-game use. It is more for me to just practice.

1 Like