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)
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)
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 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