I'm trying to detect when a block is no longer being touched but the TouchEvent doesn't fire upon the part testin being deleted. I made it simple to understand by shortening the script down to the core problem.
local object = script.Parent local testin = workspace.testin local function deleteTestin(hit) testin:Destroy() end object.Touched:Connect(deleteTestin) local function lastTouch(hit) print("hi") end testin.TouchEnded:Connect(lastTouch)
Use a value to check the change.
local BooleanValue = false local BasePart = script:FindFirstAncestorWhichIsA("BasePart") BasePart.Touched:Connect(function() BooleanValue = true end) BasePart.TouchEnded:Connect(function() BooleanValue = false end) coroutine.wrap(function() repeat wait(0.1) until not BasePart and (not typeof(BasePart) == "Instance" or not BasePart.Parent) BooleanValue = false end)()