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

How to continuosly check for a condition to be met?

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!

1 answer

✓ Accepted answer

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

7 comments

0

Please accept the answer to mark it answered, to get us both rep, and I don't like leeches.

0

Thank you so much I was clueless about this i couldnt even make my own loop anyways hope you have an awesome day or night

0

No problem, have a great one!

0

Waits prevent crashing in constant loops, might want to keep that in mind for the future. lol

0

;p

0

Avoid using "wait"s for things that change that fire a certain event. Use "script.Parent.Detector1.Touched:Wait()"

0

I honestly really hate touched

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