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