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

How to check if a specific function is running, and if so, trigger some code?

Asked by
Xyternal 247 Moderation Voter
3 years ago
Edited 3 years ago

So I have a function, and if it is running, then I want to trigger a piece of code. But I don't really know how to call my function. I haven't tried anything because I couldn't find anything. So please help. Thanks!

EDIT: The code that I want to be triggered, is the following.

for key, value in pairs(workspace:GetDescendants()) do

    if value.Name == "car" then

       value:Destroy()

    end

end
0
why not just call the function in that function that is running? You could also use simple bool variables to do this. greatneil80 2647 — 3y
0
can you please show me how? Xyternal 247 — 3y
0
i cant really call the function in the function that is running because then the whole script will fall apart. So if the function is running, then only will the code be triggered Xyternal 247 — 3y
0
but listen, i can put it in the function if you get a way to find all of the models with the same name without having to use a for loop Xyternal 247 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

local function Checker() script.Checker.Value = true --Add a BoolValue inside the script and name it "Checker" wait(2) --Instead of the wait you can add your own code here script.Checker.Value = false end while wait() do Checker() if script.Checker.Value == true then print("The function is running") -- Do something instead of the print else print("The function is not running") -- Do something instead of the print end end
0
This runs good enough. Thanks! Xyternal 247 — 3y
0
Just one question. If i change wait to some custom code, then what to i place between while and do? Xyternal 247 — 3y
0
Because in my function, there are couple loops and all, so i do need help with that too. Xyternal 247 — 3y
0
i have a script that has this but it wont work :( Xyternal 247 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
function Check() -- if you change "Check" then change the bottom check to the name of the function
    print("function check is running") -- Name Check to whatever your function name is
    -- put code in here
end
Check() -- change "Check" to your function name

0
Thanks for trying to help, but I know that the function is running. I have a loop, that runs multiple functions, and i want to see, that if the loop is in the middle of running a function, then which one it is Xyternal 247 — 3y

Answer this question