I have no idea how to stop a function. Is there any way to do so?
function fish() print("dog") wait(1) print("cat") wait(1) print("yes") end while wait() do if health.Value == 0 then fish:Stop() -- Is there anyway to do something like this? end end
So long as you have special code in the function you wish to potentially stop, yes. You simply need to have a variable to track whether or not the function should return early and then check that variable after every command that yields (wait
, GetAsync
, etc). ex:
local stopFish local function fish() stopFish = false print("dog") wait(1) if stopFish then return end print("cat") wait(1) if stopFish then return end print("yes") end while wait() do if health.Value == 0 then stopFish = true end end