How to stop a function from completing after a remote event is fired

for Example

script.Parent.Clickdetector.MouseButtonClick:Connect(function()
--function
wait(1)
--function
end)


remoteEvent.OnServerEvent:Connect(function() 
--Stop /\ that function (script.Parent.Clickdetector.MouseButtonClick:Connect(function())
--     |
end)

I hope my explanation was good, Any Help is Appreciated.

breakfunction = false
script.Parent.Clickdetector.MouseButtonClick:Connect(function()
--function
wait(1)
if breakfunction == true then
   return nil  -- this breaks the function
end
--function


end)


remoteEvent.OnServerEvent:Connect(function() 
breakfunction = true
end)

I believe there are multiple ways to do so,

1-Using Disconnect.
2-Using Variables[such as BoolValues] -with them, you’ll be able to set and check conditions.
[if a certain condition has occurred, you could return nil, and stop the function].

For e.g :

You could pass a variable[let’s say , a boolean], to the server, and if it’s true, stop the function by returning nil]

how would I use disconnect? I don’t want it to check each time.

Disconnect prevents it from running the function again, doesn’t interrupt it.

1 Like