Destroying a local function

so what im trying to do is destory or disconnect() a function that i made, like for example when using Function:Disconnect() for roblox functions but rather for functions that i have created
heres an example

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

local function CustomFunction(Variable, Variable)

 local RemoteEventFunc

 RemoteEventFunc = RemoteEvent.OnClientEvent:Connect(function() -- this event fires right away after the CustomFunction is called
 
  -- somehow disconnect the parent function named "CustomFunction"

  RemoteEventFunc:Disconnect()

 end)

print("This Shouldn't Print") -- this shouldnt print because the parent function what have disconnected if there is a solution

end

CustomFunction(Variable, Variable)

so if the example is not clear what i want to achieve is that when the remote event fires the script disconnects the parent function which is the “CustomFunction” the same way the remote event function disconnected

(sorry if there is any errors in the code i wrote all of it in here)

So you want to deactivate functions that you created correct?

1 Like

yes

character limit

Just do something like this

local func = function() 
    print("hello")
end

--Disable Function--

func = function()end
1 Like

and this also can disable the function inside of it right?

I have modified this script to fulfill your needs. This is what I did.

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

local function CustomFunction(variable1, variable2)
    local shouldContinue = true
    local RemoteEventFunc

    RemoteEventFunc = RemoteEvent.OnClientEvent:Connect(function()
        shouldContinue = false
        RemoteEventFunc:Disconnect()
    end)

    if shouldContinue then
        print("This Shouldn't Print")
        -- Add the rest of your CustomFunction logic here
    end
end

CustomFunction(value1, value2)
1 Like

This will make it so when you call the function, nothing will happen.

sorry for the delayed respond but i do want to call the function again, i just want to deactivate all of the things inside the function UNTIL it is called again

i will also try this solution thank you for the help

Put all of your code in a if statement and use a variable to determine whether the functions inside can be called or not like @ReloadedO stated.

1 Like

yes that is what im doing currently, ill update you if it worked

i just realised it was a problem in my original code, i had a loop where it yielded the RemoteEvent that was supposed to disconnect all the functions, i just moved the RemoteEvent to a line before the loop ran so it would detect the event before the loop ran, i appreciate all the help but it was something on my behalf.

idk who to give the solution because you two both are correct

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.