- What do you want to achieve?
I want to kill a thread from running when a condition is true.
- What is the issue?
I manage to kill the thread, but it seems like the event I created is still recognized/not dead.
- What solutions have you tried so far?
I have heard about the task.cancel() method, but I am not very confident in using it within my script or finding a thread that clearly explains how to use task.cancel().
local function someFunction()
local dead = false
local function killThread()
dead = true
print("dead")
end
tool.Unequipped:Connect(killThread) -- not sure how to kill this line
wait(seconds)
if dead == false then
--Execute code here
end
end
Although this satisfied the condition of killing the thread, “gunMechanic.Weapon.Unequipped:Connect(killThread)” does not and will stack upon each time I unequip my tool (Unequipped first time = print “dead” 1x, Unequipped second time = print “dead” 2x, etc).
How do I stop this from happening?