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?
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
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.