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

Why won’t it return the variable?

I want to return x and y from the functions but when I put in return x or y, it still says it is undefined. Could someone help me figure out where I’m going wrong?

import time
usernames = 'Codswollop'
passwords = 'Fishcake420'

def password():
  x = input('Please enter your password: ')
  if len(x) < 8:
    print('Password not long enough. Please try again. ')
    password()
  else:
    print('Thank you!')
    return x

def username():
  y = input('Please enter your username: ')
  contains_digit = False #starts as false
  for i in list(y): #repeats the amount of times there are characters in the username.
    if i.isdigit(): #if i, the iteration (each character), is a digit:
      contains_digit = True #set to true because a digit was detected
  if contains_digit == True: #if a digit was detected then:
    print('Contains digit. Please try again. ')
    time.sleep(1)
    username() #restarts function, asking for username again
  else:
    return y


username()
password()

if y == usernames:
  if x == passwords:
    print('access granted')

2 comments

0

bro take a look at lua syntax.

0

@CaioAlpaca its python not lua, I thought I could post python on here but oops

1 answer

✓ Accepted answer

i'm pretty sure this site is for questions about roblox lua, not python, but i'll answer anyway :P

you do set x and y, but only within the scope of the password and username functions

you need to do

y = username()
x = password()

or else the y and x variables are never set outside of that function

alternatively you could also just do this

if username() == usernames and password() == passwords:

also, when you retry in your functions (after the password isn't long enough or the username contains numbers), you need to add return, so it'd be return username() and return password()

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