part.Touched prints twice

I don’t know what im doing wrong but this code seems to be printing twice when connecting part.Touched

local function onTagPad(tag)
	local debounce = false
	
	tag.Touched:Connect(function(hit)
		if not debounce then
			debounce = true
			if (hit.Parent:FindFirstChild('Humanoid')~=nil) then
				local char = hit.Parent
				local HRP = char:FindFirstChild('HumanoidRootPart')		
				local rayOrigin = hit.Parent.PrimaryPart.CFrame.Position
				local rayDirection = tag.CFrame.Position - rayOrigin
				local raycastParams = RaycastParams.new()
				raycastParams.FilterDescendantsInstances = {hit.Parent}
				raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
				raycastParams.IgnoreWater = true
				local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

				if raycastResult.Normal then
					if CollectionService:HasTag(tag, tagConfig.JumpPad) then
						onJumpPad(tag, hit)
					elseif CollectionService:HasTag(tag, tagConfig.DashPad) then
						onDashPad(tag, hit)
					end
				end
			end
			print(hit)
			task.wait(0.1)
			debounce = false
		end
	end)
end

--// Tag Check
for _, part in (CollectionService:GetTagged(tagConfig.JumpPad)) do
	onTagPad(part)
	part.Orientation = Vector3.new(0,0,0)
end

CollectionService:GetInstanceAddedSignal(tagConfig.JumpPad):Connect(function(pad)
	onTagPad(pad)
	pad.Orientation = Vector3.new(0,0,0)
end)

try to increace the wait timer

1 Like

its printing twice way before it even checks for the debounce tho, if i put it right under

	tag.Touched:Connect(function(hit)

it still prints twice, its not a debounce issue

its really late so im heading to bed, but if anybody helps while im asleep, thank you.

Because the onaddedsignal for tags and “add all existing tags” may be fired on the same part

1 Like