The Issue About Touched Event, Triggering Twice When Unneeded

Hey!

So I have three spawn locations, a big part (transparent, not collidable) that acts as area to name the location.

The big part was supposed to fire Touched event when the player touches the big part (so as to give information about the fact the the player is in another area.)

But there is a problem with this.
When the gameplay pauses, sometime it causes it to trigger twice. This happens when the player joins and is teleported to one of these spawn locations, anyone know why?




VIDEO BELOW




PICTURE SHOWING THE BIG PART




A script for teleporting the player to these spawn location when joining the game:

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

local locations = CollectionService:GetTagged("SpawnLocation")

local function onCharacterAdded(character: Model)
	local humanoid : Humanoid = character:FindFirstChild("Humanoid")
	local location = locations[math.random(#locations)]
	
	local locationCFrame = CFrame.new(location.CFrame.Position)
	locationCFrame *= CFrame.Angles(0, math.rad(150), 0)
	print(locationCFrame)
	
	character:PivotTo(locationCFrame)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	
	if player.Character then
		onCharacterAdded(player.Character)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)



Another script for handling Touched Event and for the big part.

-- Service
local ServerStorage = game:GetService("ServerStorage")

-- Libraries


-- Events
local OnWorldEnter = ServerStorage["Bindable Events"]["Universe Events"].OnWorldEnter
local OnWorldLeave = ServerStorage["Bindable Events"]["Universe Events"].OnWorldLeave
local OnAreaEnter = ServerStorage["Bindable Events"]["Universe Events"].OnAreaEnter
local OnAreaLeave = ServerStorage["Bindable Events"]["Universe Events"].OnAreaLeave

-- Module Services


-- Initalizing Variables
local worldsList = workspace.Worlds:GetChildren()
local touchAreasList = {}


-- Scripts
for _, world in pairs(worldsList) do
	local areasFolder = world.Areas:GetChildren()
	
	for _, area in pairs(areasFolder) do
		local touchPart = area.Touch.touchArea
		table.insert(touchAreasList, touchPart)
	end
end

for _, touchArea : Part in pairs(touchAreasList) do
	print("connecting")
	touchArea.Touched:Connect(function(partTouching)		
		if partTouching.Name == "HumanoidRootPart" then
			print("true!!!")
		end
		

	end)
end

The Touched event normally needs a debounce, espectially with players since the players parts will touch multiple times.
Try:

-- first line at the beginning of the script
local debounce = false

-- then in your function
for _, touchArea : Part in pairs(touchAreasList) do
	print("connecting")
	touchArea.Touched:Connect(function(partTouching)
        if not debounce then		
		if partTouching.Name == "HumanoidRootPart" then
            debounce = true
			print("true!!!")
            task.wait(1)
		end
        debounce = false
	end)
end

That is not my issue, it normally works without this debounce.

The issue is that when gameplay paused shows up, it fires twice.
It is also fired twice because two humanoidrootparts touched?

So what is ‘gameplay paused’?
I don’t see anything about it in these scripts. If its in another script then possibly that section of code is where the error is.

image
It’s like this. Just that you didn’t see fast enough

And I was wondering how I could get rid of this that was causing the weird problem.

To add to the debounce you could make a table and store the players name in the table anytime a player touches the part, and check if their name is not in the table before doing any code

Then simply remove the player name from the table after how ever long you want