Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
M9F 94
4 years ago

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

Log in to vote
2
Answered by 4 years ago

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)()
0
I sent you a friends req on my account called M9F. Mind accepting? M9F 94 — 4y
Ad

Answer this question