Why is this not capturing the password?

I’ve used some AI to help solve this issue, but it didn’t do anything. It keeps saying that the password field is empty when the correct password is there…

local textBox = button.Parent.TextBox
local logInFrame = button.Parent.Parent.LogIn
local wrongPasswordLabel = script.Parent.Parent.WrongPassword -- Assuming you have a label for wrong password message

-- More obfuscated new password
local correctPassword = "A"

-- Rate limiting variables
local attempts = 0
local maxAttempts = 5
local lockoutTime = 10 -- seconds
local isLocked = false

button.MouseButton1Click:Connect(function()
	if isLocked then
		wrongPasswordLabel.Text = "Too many attempts. Try again later."
		wrongPasswordLabel.Visible = true
		return
	end

	local enteredPassword = textBox.Text

	-- Basic input validation
	if enteredPassword == "" then
--		wrongPasswordLabel.Text = "Password cannot be empty"
		wrongPasswordLabel.Visible = true
		wait(3)
		wrongPasswordLabel.Visible = false
		return
	end

	if enteredPassword == correctPassword then
		script.Parent.Parent.Parent.Parent.Password.Visible = false
		script.Parent.Parent.Approved:Play()
		script.Parent.Parent.Parent.Parent.LogInScreen.Visible = false
		script.Parent.Parent.Parent.Parent.ImageLabel.Visible = false
		script.Parent.Parent.Parent.Parent.TurnOff.Visible = false
		script.Parent.Parent.Parent.Parent.Users.LogIn.Visible = false
		script.Parent.Parent.Parent.Parent.Users.ImageLabel.Visible = false
		script.Parent.Parent.Parent.Parent.Users.SelectedUser.Visible = false
	else
		attempts = attempts + 1
		if attempts >= maxAttempts then
			isLocked = true
--		wrongPasswordLabel.Text = "Too many attempts. Try again later."
			wrongPasswordLabel.Visible = true
			wait(lockoutTime)
			isLocked = false
			attempts = 0
		else
--			wrongPasswordLabel.Text = "Incorrect password"
			wrongPasswordLabel.Visible = true
			wait(3)
			wrongPasswordLabel.Visible = false
		end
	end
end)```

Just below this line:

local enteredPassword = textBox.Text

Are you able to put in this below it:

print(enteredPassword)

I’m going to guess it’s empty/nil, in fact, try this instead, replace:

-- Basic input validation
if enteredPassword == "" then

with:

-- Basic input validation
if enteredPassword == "" or enteredPassword == nil then

Let me know what these do. :slight_smile:

2 Likes

My guess is that you’re using a server script, which doesn’t detect changes when the player edits the text from the TextBox. Try changing it to a LocalScript, then test it again.

2 Likes

No no, it is used on a surfaceGUI, so I’m using a nornal script.

Why don’t you move the surface GUI to StarterGui, replace the ‘normal script’ with a local script, and just set the Adornee of the GUI to the object that initially parented to the GUI? It should resolve the problem

2 Likes

Scripts should rarely be associated with UI, especially if that UI involves client interaction

No, this code is meant for a surfaceGUI.

None of these work, I still don’t get why…

Yeah? The information I provided is still in regards to a surface GUI?

I just realized what the issue was. The TextBox was capturing the text correctly, it’s just that the TextBox only works on the client, so I have come up with a better solution. It is to use a keyboard model that works inside of workspace.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.