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

Is there a way to stop a function almost immediately?

Is there a way to stop a function almost immediately stop a function even if it is currently running. I have been looking on the wiki but theres nothing.

I know theres a :disconnect() for a debounce, but is there anything for a :disconnect() or something for a function() like maybe..

time=10

function TEST() 
for i=time,0,1 do
print(i)
if time==5 then TEST:disconnect() end
end
end

TEST()

1 answer

✓ Accepted answer

return exits a function (optionally with a value).

time = 10

function timer()
	for t = time, 0, -1 do
		if time == 5 then
			return
		end
	end
end

timer()

I'm not exactly sure why you're doing a loop like that, though. You should count down to just 5 if that's what you mean to say.

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