How do I make a function run only after the first one does

Hey. So my code works, but it’s just the second line says “Incorrect” immediatly, because the user doesn’t get a chance to re-enter the password. See here

local Text = script.Parent

local MainGui = script.Parent.Parent

local EnterButton = MainGui.TextButton

Text.PlaceholderText = "Create a Password"

EnterButton.Text = "Create!"

EnterButton.MouseButton1Up:Connect(function()

PasswordSave = Text.Text

print(PasswordSave)

EnterButton.Text = "Saved Password!"

end)

EnterButton.MouseButton1Up:Connect(function()

if Text.Text == PasswordSave then

print("Correct!")

else

print("Incorrect...")

end

end)

How do I make it so the function only runs after the first one does?

1 Like

Couldn’t you just create a sequence of statements within a single event function?

Not too sure how you want this to function, but you could almost like add a debounce so the button can’t be interacted with again, and then add in a wait statement to update the text to something else.

1 Like

Make individual functions for both functions and connect the MouseButtom1Up event in the order you want the functions to be in.

This doesn’t seem practical to me, as both events are the same, you could simply just add your statements within a single function instead.

Both events also won’t execute at exactly the same time, depending on which event function is executed first with whatever the task scheduler is handling, so that could also lead to inconsistency.

That’s also not how :Connect() was designed. You pass some callback function as an argument through :Connect(f), and it registers that function to be executed at some point when the event fires.

Order is not thoroughly considered.

1 Like