Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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:


function ValueChecker()
	local Value = game.Players.LocalPlayer.Powers.Turret.Value
	local key = Value
	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)

while true do
	wait(0.5)
	ValueChecker()
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:

while true do
	wait(0.5)
	ValueChecker()
end)

k bye

This discussion is preserved as it was. New answers, comments, and votes are closed.