Hello! I was wondering how to stop a function from running whenever a value is changed. This is probably very simple but I just can’t seem to figure it out. Here is an example of what I want to accomplish:
--example (in a module script)
local module = {}
local bool = game.workspace.BoolValue
function module.PrintNumbers()
task.spawn(function()
bool.Changed:Connect(function()
if bool.Value == true then
--stop this function from continuing
end
end)
end)
print(1)
task.wait(1)
print(2)
task.wait(1)
print(3)
task.wait(1)
print(4)
task.wait(1)
print(5)
task.wait(1)
print(6)
task.wait(1)
print(7)
task.wait(1)
print(8)
task.wait(1)
print(9)
task.wait(1)
print(10)
end
return module
If anyone could help, that would be greatly appreciated!