Thanks so much for your patience AFRLme.
The key surrounded by lights moves every rotation of the other 3 keys, no matter what, and is required to solve the puzzle. Because this key should have only three sequentially moves from position 0 to position 270 (each light turns on each rotation). If you go over the 3 moves, the key is reset.
But you need to open three locks and simultaneously have the fourth key, three moves in sequence.
I mean that you can rotate other keys all you want, but the endgame should be in three sequential step for the fourth key.
The keys reset when you reach the position 270 (this is why I haven't been able to set up a reverse rotation by 90 degrees, I tried setting ceil instead of floor, but as I said I'm a noob with Lua) and each key, sometimes, rotate another key just to add a bit of difficulty to the puzzle (but I think I've only added difficutly to my programming Ahahah).
I will try your suggestion hoping to get something that works and sorry for my bad English
