How to turn a .Touched into an if statement?

Hello! Today I was wondering how to turn a .Touched into an if statement. For example, when a function fires that a .Touched is in, the .Touched gets “activated”, so even when the the isn’t fired, the .Touched still fires.

Heres a script example:


local function mine(hit)
	if debounce == false then
		print(hit)
		debounce = true
		task.wait(1)
		debounce = false
	end
end

local function mineAnimation(input,_gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if track.IsPlaying == false then
			if character:FindFirstChild(pickaxeTool.Name) then
				track.Priority = Enum.AnimationPriority.Action
				track.Looped = false
				track:Play()
				damagePart.Touched:Connect(mine) --I have to turn this into an if statement
			end
		end
	end
end

userInputService.InputBegan:Connect(mineAnimation)

Thanks for the help!

1 Like

Any event can have Wait() called on it instead of Connect(). Is that what you mean? For example this is how you make code wait for a sound or tween to finish.

No I mean like when the mineAnimation function fires, the .Touched gets “activated” so even when the mineAnimation isn’t fired, the .Touched still fires.

It already does do that, once you connect an event it stays connected unless the subject is removed or Disconnect is called on the object returned from Connect.

Yeah but after you disconnect you need to be able to fire that function again like an if statement

Use workspace:ArePartsTouchingOthers( partList: Objects, overlapIgnored: number)