FireAllClients() seemingly sends two signals

In a server module script, I use FireAllClients() on a remote event, and I know it only fires once from the server because of print detection. Here’s the server script:

function MonsterHandler:_SpawnMonster(monsterType: string, pathID: string, pathProgress: number, multiplier: number): (Monster?, string)	
	-- Code for spawning the monster, unrelated
	
	local monsterRenderInfo = {
		monsterID = monsterID,
		modelName = monster.modelName or monster.name,
		pathProgress = 0,
		pathID = monster.pathID,
		movementAnimationID = monsterConfig.movementAnimationID
	}
	
	SpawnMonster:FireAllClients(monsterRenderInfo)

	return monster, "Monster successfully spawned."
end

function MonsterHandler:SpawnMonster(monsterType: string, pathProgress: number?, multiplier: number?): (boolean, string)
	for _, path in ipairs(self.paths) do
		local result, reason = self:_SpawnMonster(monsterType, path.id, pathProgress or 0, multiplier or 1)
		if not result then return false, reason end
	end
	return true, "Monster successfully spawned"
end

I have verified that there is only one path in self.paths, which is not an issue. Here is the local script that receives the (seemingly two) signals:

local function spawnMonster(monsterRenderInfo: MonsterRenderInfo)
	-- Code for spawning the monster on the client, unrelated
	
	return true, "Monster successfully spawned on client."
end

SpawnMonster.OnClientEvent:Connect(spawnMonster)

I’ve looked through all of my other scripts, and there is no trace of other activations from other scripts. I even tested sending a custom string from my server script stating, “This is from {server script name}” to confirm that the signal comes from the same location, which it does. I’m absolutely stumped and have no clue how to fix this issue. I’ve even run debugs to determine the RemoteEvent is indeed receiving two signals instead of the spawnMonster function running twice.

Is it a LocalScript and not a Script with it’s RunContext set to Client? Where is your LocalScript located and can you assure it’s only connecting once?

Have you also tried creating a fresh LocalScript with a sample connection and see if that prints once?

1 Like

Welp, it was exactly what you said. I completely forgot that I changed the context when I was testing. It is fixed now. Thank you so much!

Also, do you know why changing the context of a script instead of using a LocalScript causes this to happen? It’s very interesting.

Scripts with it’s RunContext set to Client means that it can run code where it usually cant, like the workspace or ReplicatedStorage (exluding server storages, obviously).

This also means that the script can now run inside the StarterPlayerScripts. When the player joins, a new copy of that script clones to their PlayerScripts. Now you have 2 client scripts that are running instead of 1.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.