TouchEnded triggering after unequipping a tool?

I don’t know if this is the right category, because it could be an engine bug.

The problem I have is that I made a “zone system” where you basically touch a hitbox and a gui saying “now entering …” pops up. It has a debounce so that it doesn’t pop up again until .TouchEnded is triggered, which for some reason is triggered after unequipping a tool, it disables the debounce and the message pops up again.

Is there any way to solve this or it’s an engine bug?

show script (kgewpwepk[pekgoweko)

local debounce = false
local text = "factory"

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		if not debounce then
			debounce = true
			local char = hit.Parent
			local plr = game.Players:GetPlayerFromCharacter(char)
			plr.PlayerGui.Zones.MainFrame.ZoneName.Text = text
			plr.PlayerGui.Zones.MainFrame:TweenPosition(UDim2.new(0.5, 0, 0.1, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,0.5)
			wait(3)
			plr.PlayerGui.Zones.MainFrame:TweenPosition(UDim2.new(0.5, 0, -0.1, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,0.5)
			script.Parent.TouchEnded:Connect(function(hit)
				if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
					wait(0.5)
					debounce = false
				end
			end)
		end
	end
end)

the script works, it’s just the .TouchEnded being triggered when it shouldn’t be

because the tool is also a child of the character I guess and whenever you unequip it TouchEnded fires

oh true, im dumb and i didnt realise

wait, but it says script.Parent, when for the tool it should be script.Parent.Parent

ye just check if the “hit” was Tool and if it was tool then just ignore it

I’m using this
if hit.Parent:FindFirstChildWhichIsA("Humanoid") and not hit.Parent:IsA("Tool") then
but it still gets triggered?

can you print(hit)
sdadsadsasadasdas

apparently, i was right at first…
when i unequip the tool every part inside the body (except the handle) gets printed again

btw heres a video proof https://gyazo.com/9a1b7d7c0ab99d60e893b38e0d9adc22

Touch Ended usually fires from anything it’s touched, you could detect if the humanoidrootpart.cframe or pos is inside the box / casted and once it realizes your in there make it where it won’t repeat it again until it detects you out of the box.

Touch Ended isn’t reliable on Zone-Detections, I recommend looking at Zone+ or some other scripts in the Dev Forum.

2 Likes

It works fine to me, thats the only problem i’ve seen so far.

I never heard of what you just said and im kinda new so it’s probably gonna be hard to use

Ooh, yeah should’ve made a link towards it. But atleast it’s working fine, if you do want to see it just let me know.

Split this line into two separate conditionals.

the touchended got triggered anyway, I can’t find the reason but it just does