How can I disconnect a function? For example;
function oc(ack) find=ack.Parent:FindFirstChild("Humanoid") if find then find.Health=50 end end script.Parent.Touched:connect(oc) script.Parent.TouchEnded:disconnect(oc) --Would this work? If not, how can I disconnect the function?
Connections are actually instances of RBXScriptSignal. Creating one (with connect) returns a instance of RBXScriptConnection. And there's a method that allows you to disconnect them.
So
connection = script.Parent.Touched:connect(function(part) print(part.Name) connection:disconnect() end)
game.Workspace.Yellow.Touched:connect(function(ack) find=ack.Parent:FindFirstChild("Humanoid") if(find)then find.Health=50 end end)
Not too sure what you meant by disconnect but I guessed you meant make it only run once and if so no code will run twice without a loop inside of it. The code above is a tad more efficient that your own and will only run once due to the non-existence of a loop.
There's only two methods I can think of doing this, (although you'd might want to look up breakpoints)
Method 1
Call a function that doesn't exist, it's messy, but it does the job
part = Workspace.Part part.Touched:connect(function(hit) --code code code... callaFuntionThatDoesnExist() end)
Method 2
Use a debounce
part = Workspace.Part active = true part.Touched:connect(function(hit) if not active return end --code code code... active = false end)