I’ve been working on a system and thought that if THIS happened, the function should stop.
My system is a survival game with abilities that tend to have timers before something runs. I’ve just been wanting to know if I can disconnect the ran function when their health decreases.
Ex:
local functionConnection = function()
-- do some stuffs
end
functionConnection()
character.Humanoid.HealthChanged:Connect(function(newHP)
if newHP < currentHP then -- Checks if they LOST hp
BuildingConnection:Disconnect() -- disconnection
end
end)
This is current what I have, but the disconnection does not work..
first of all, your code shows 0 clues as to what BuildingConnection is, I’m assuming you meant functionConnection?
if you want to terminate a function, that is yielding, task.spawn it and cancel whenever you want with task.cancel, or have flags that only suffice the functions run conditions (return if needed at some point)