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

How can I add a loop for a particular piece of Code and I can access it later?

Asked by
Ifesol 4
3 years ago

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.

1 answer

Log in to vote
0
Answered by 3 years ago

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:

1function 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)

1while true do
2    wait(0.5)
3    ValueChecker()
4end

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:

1while true do
2    wait(0.5)
3    ValueChecker()
4end)

k bye

Ad

Answer this question