How can return a value to it original value?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Iplayx

Var servant amount = 1
Func on checkbutton toggle ( button_pressed):
If servant amount = 0:
Checkbutton.disabled = true
Elif button_pressed:
Servant amount -= 1
Servant amount += 1

Ok so i have something like this for my code. What i want it that of the player doesn’t have servant available he can’t toggle the button.
If he has servant available he can toggle the button to turn it on when this happens it take away 1 servant.
If the player toggle off the checkbutton then he will receive the servant back.

:bust_in_silhouette: Reply From: Wakatta

Now this is a hard one since your code is an infinite loop that achieves nothing.

The only way to get what you want is to offset your code to another button or part in your script, most likely the focus_entered signal.

var servant_amount = 1

func on_checkbutton_toggle ( button_pressed):
    if button_pressed:
        servant_amount -= 1
        servant_amount += 1

func on_checkbutton_focus_entered():
    $Checkbutton.disabled = servant_amount == 0