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

How to stop a function while its running?

2 answers

setfenv(func,{})

1 comment

0

Works, but makes an error. I would like a more efficient approach to this.

What you can probably do if its a while true loop or some other loop is check if a value you defined earlier is false or true

For example:

local Check = false

coroutine.wrap(function()
	while Check == false do
		print("Running")
		wait(0.1)
	end
end)()

wait(5)

Check = true -- This will make the function stop running

You could also use the same logic for a function you have defined:

local Check = false

function GoodFunction()
	coroutine.wrap(function()
		if Check == false then
			repeat
				print("Good")
				wait(0.1)
			until Check == true
		end
	end)()
end

GoodFunction()

wait(5)

Check = true

Let me know if you have any issues!

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