local connections = {}
CollectionService:GetInstanceAddedSignal("TestTag"):Connect(function(instance)
connections[instance] = task.spawn(function()
local testProximity = instance.ProximityPrompt;
testProximity.Triggered:Connect(function(player)
task.wait(1)
print("proximity first test")
task.wait(3)
print("proximity second test")
end)
task.wait(5)
print("task first test")
task.wait(2)
print("task second test")
end)
end)
CollectionService:GetInstanceRemovedSignal("TestTag"):Connect(function(instance)
task.cancel(connections[instance])
end)
I thought that closing this task would also stop the triggered function. Now I wanted to disconnect the proximity triggered function but it didnt work. I assume the disconnect only disconnects it from working but doesnt stop the function itself. Now how would I do this?
All I want to do is cancel everything inside the task after the tag has been removed.
Thanks again, this wouldnt stop the function tho, because it would only run once the event is triggered.
What I basically want is the triggered function to stop completely. So the task.wait and stuff dont run even after the function has been triggered. I assume theres no way to do it.
local t
function Task(p)
t = task.spawn(function()
print(p)
task.wait(5)
print("oof")
end)
end
local A = ProximityPrompt.Triggered:Connect(Task)
A:Disconnect()
task.cancel(t)
local co = coroutine.create(function()
-- code
end)
-- within connection:
coroutine.resume(co)
-- Disconnecting:
connection:Disconnect()
coroutine.close(co) -- coroutine has to be running for this to work
local connections = {}
local c
CollectionService:GetInstanceAddedSignal("TestTag"):Connect(function(instance)
connections[instance] = task.spawn(function()
local testProximity = instance.ProximityPrompt;
c = testProximity.Triggered:Connect(function(player)
task.wait(1)
print("proximity first test")
task.wait(3)
print("proximity second test")
end)
task.wait(5)
print("task first test")
task.wait(2)
print("task second test")
end)
end)
CollectionService:GetInstanceRemovedSignal("TestTag"):Connect(function(instance)
task.cancel(connections[instance])
c:Disconnect()
connections[instance] = nil
end)
local connection = script.Parent.Triggered
thread = nil
c = connection:Connect(function()
thread = task.spawn(function()
while wait() do
print("R")
end
end)
end)
wait(5)
task.cancel(thread)
c:Disconnect()