Guys here is a betetr way to explain what i want .
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = 0
delay(3)
break
end)
I kinda want a break , but for a funtion if that makes sense
Guys here is a betetr way to explain what i want .
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = 0
delay(3)
break
end)
I kinda want a break , but for a funtion if that makes sense
No that will not work unfortunately, break
doesn’t do anything to the event
I am aware . I said im trying to explain it better to you . I want a break but made for events
Oh if you want a break then @jakebball2019 is correct, you want to use Disconnect. It was not very clear to me what you wanted in the question.
You need to declare the connection outside of the callback like this:
local connection = part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = 0
end
end)
delay(3, function() connection:Disconnect() end)
I can not really make out what the article means with the disconnect
oooo . Wait is it like turning the funtion into a variaable then telling it to stop by saying disconect?
basically, I recommend using wait instead of delay as delay is only useful if you pass a function as a second parameter that runs as delay is meant to run a function after the delay without having to yield the script but if you want to yield completely and stop the script use wait().
Reformatted so you can see the example better:
local connection = part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = 0
end
end)
delay(3, function()
connection:Disconnect()
connection = nil
end)
True . Well thanks guys . This helped and both of you helped me . I do not know who to mark as solution .
thats aight, it dont really matter
To clarify, would you call the delay() once the tool is activated? Wouldn’t it just run instantly the way you have it? I understand if you just wrote it out that way for demonstration, I’m just not exactly sure myself.
I believe he wants the tool to damage people for 3 seconds, so the delay should run immediately when the “tool damage” is activated.
This code should be put in the Activated connection callback.