Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Solved) How do i check if multiple variables are true or not in an if-statement?

Asked by
Klui36 45
1 year ago
Edited 1 year ago

so basically i want to do a movement system for my tool. For it to work i need to check if the different Keys (W key, A key, S key, D key) are pressed. Im using an if statement for it but it wont work because you cant put multiple "ands" in an if statement. Heres the code that im stuck with:

if wPressed == true and aPressed == false and sPressed == false and dPressed == false then

Does anybody have a solution to my question?

1 answer

Log in to vote
0
Answered by 1 year ago

it wont work because you cant put multiple "ands" in an if statement.

That is incorrect. There is no limit on how many times you use and in an if statement.

If the code you provided is not working, it means that wPressed is not the only boolean that is set to true. Try debugging it by using prints to check the variables to see if they are the correct boolean.

0
Thank you very much good sir. You saved me a TON of time today. Klui36 45 — 1y
Ad

Answer this question