Help with a value checker

How do I make a function that constantly checks until a value is true? Then if the value is true it does something.

Sounds like you want a while loop. Here is a code example below:

ValueIsTrue = false   

function TrueCheck()
    While ValueIsTrue == false do

    -- Add code here for when value is true


More info on while loops can be found here: Introduction to Scripting | Roblox Creator Documentation

task.wait(0.5) --you can change this on how often it checks
until ThisValue == true

--Code to run after it's true.

This would enable a script timeout and kill the script. There needs to be a task.wait() inside the loop. This will run a million times instantly without the task.wait().

1 Like

I see you added wait() to your script. This should be task.wait() because wait() is being deprecated.

Saying this value is an instance or an attribute there are appropriate events for them, you can check on their respective page.

If this is regarding a variable, you would so something like

local RunService = game:GetService("RunService")
local Variable = False
   while not Variable do
       RunService.Heartbeat:Wait() -- you can also task.wait()
   --your code to run here

Reason for spawning is not stopping the whole code when waiting for it to change.

Thanks for letting me know! I found the post about task.wait().

1 Like

Shouldn’t you use a changed event instead?

OP did not specify if it was a variable or an instance value.

1 Like

wouldn’t a while true loop work best?

Here is an easier way IntValue | Roblox Creator Documentation

OP didn’t specify if it was an IntValue or a variable.