I need a code to continuously check if a certain condition has been met. I tried using if statements, but I noticed they only check for it when the script is run, or they are called in a function. I tried using a while loop, but, That was catastrophic. It almost crashed studio. I don't even know if a for loop would work because when I typed for #script.Parent.Detector1:GetTouchingParts() == 3 do
, the hashtag was underlined red. I am looking for a way to run the function only once, and only when the certain condition is met. Here is the part I need help with:
if script.Parent.Detector1:GetTouchingParts() == 3 then -- My dumb attempt at using an if statement ? -- print("touching three parts") end
Help is greatly appreciated. Thanks!
You can easily add a while loop at the beginning. Example:
while wait(.1) do --Same thing as while true do but adds a wait of .1 seconds, used to prevent crashing --code here end