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

How to continuosly check for a condition to be met?

Asked by
Faazo 84
6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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
0
Please accept the answer to mark it answered, to get us both rep, and I don't like leeches. DaWarTekWizard 169 — 6y
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 Faazo 84 — 6y
0
No problem, have a great one! DaWarTekWizard 169 — 6y
0
Waits prevent crashing in constant loops, might want to keep that in mind for the future. lol DaWarTekWizard 169 — 6y
View all comments (3 more)
0
;p DaWarTekWizard 169 — 6y
0
Avoid using "wait"s for things that change that fire a certain event. Use "script.Parent.Detector1.Touched:Wait()" hiimgoodpack 2009 — 6y
0
I honestly really hate touched DaWarTekWizard 169 — 6y
Ad

Answer this question