I need to add a loop to a piece of code so it continuously checks whether the value has been changed but when I do that it also affects other parts of the code.
' local Value = game.Players.LocalPlayer.Powers.Turret.Value local key = Value script.Parent.Text = Value '
I need to add a loop for this code but if I do it affects the code below because I have already defined value and key and also if I cover the code with a loop it affects it.
You can turn this block of code into a function and then use the while loop to check if the value has been changed like so:
1 | function ValueChecker() |
2 | local Value = game.Players.LocalPlayer.Powers.Turret.Value |
3 | local key = Value |
4 | script.Parent.Text = "Value" |
and then I after you're done with this you can continuously call the function using while true do like so (include this at the end or after your function)
1 | while true do |
2 | wait( 0.5 ) |
3 | ValueChecker() |
4 | end |
you can change the wait to however long you want it to be but don't delete it as it reduces lag a ton. Also if your "end" at the end of the while true do event is underlined, add a bracket at the end like this:
1 | while true do |
2 | wait( 0.5 ) |
3 | ValueChecker() |
4 | end ) |
k bye