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

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

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

4 comments

0

why not just call the function in that function that is running? You could also use simple bool variables to do this.

0

can you please show me how?

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

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

2 answers

✓ Accepted answer

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

4 comments

0

This runs good enough. Thanks!

0

Just one question. If i change wait to some custom code, then what to i place between while and do?

0

Because in my function, there are couple loops and all, so i do need help with that too.

0

i have a script that has this but it wont work :(

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

1 comment

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

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