Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to see if a a touch was stopped on a block that has been deleted? I accept answers

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)

1 answer

✓ Accepted answer

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)()

1 comment

0

I sent you a friends req on my account called M9F. Mind accepting?

This discussion is preserved as it was. New answers, comments, and votes are closed.