script.Parent.BladePart.Touched:connect(function(hit)
print(hit.Parent.Name)
end)
it works fine but how do i break a function or make it run again until something happens or a period of time
script.Parent.BladePart.Touched:connect(function(hit)
print(hit.Parent.Name)
end)
it works fine but how do i break a function or make it run again until something happens or a period of time
I only learned about an interesting method that solves your problem around half a month ago; the disconnect() method! It does exactly what you'd expect: it disconnects the connection from an event. In order to do so, you must give your event a variable name. Here, I'll show you how yours should look:
local thisEvent = script.Parent.BladePart.Touched:connect(function(hit)
print(hit.Parent.Name)
end)
Now say you want to disconnect that event named "thisEvent". Simply use this line of code:
thisEvent:disconnect()
This will effectively severe the event listener.
Note: you can also do this like so:
function hitFunc()
print(hit.Parent.Name)
end
local thisEvent = script.Parent.BladePart.Touched:connect(hitFunc)
--Somewhere else:
thisEvent:disconnect()
Hoped this helped! If you need any other help, just ask! :)
Here is the wiki page for Connections/disconnect(): RBXScriptSignal
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
you can use "break" to stop it
k, ill try it