Remote Event (FireClient) Receiving twice

Server:

function module:ServerToClientManageSound(PlayerAlvo:Player, AudioPlayer:AudioPlayer)
	if PlayerAlvo ~= nil then
		print("Function module:ServerToClientManageSound")
		ClientAudioPlayerSend:FireClient(PlayerAlvo, AudioPlayer)
		print("DEBUG 1")
		if PlayerAlvo.Character.Som:GetAttribute("GerenciarVolumeLoop") == false then
			PlayerAlvo.Character.Som:SetAttribute("GerenciarVolumeLoop", true)
		end		
	end	
end

Client:

local RS = game:GetService("ReplicatedStorage")
-- REMOTE EVENTS //
local ClientAudioPlayerSend = RS.Functions.Som:WaitForChild("ClientAudioPlayer")

ClientAudioPlayerSend.OnClientEvent:Connect(function(AudioPlayerRecebido:AudioPlayer )
	print("ClientAudioPlayerSend Client Recebeu event! AudioPlayer Parent:"..AudioPlayerRecebido.Parent.Name)
	if AudioPlayerRecebido ~= nil then
		if not table.find(AudioPlayers, AudioPlayerRecebido) then
			print("CLIENT: DEBUG 1")
			table.insert(AudioPlayers, AudioPlayerRecebido)
		end
	end
	print("CLIENT: DEBUG 2")
end)

OUTPUT:

Server: Function module:ServerToClientManageSound
Server: DEBUG 1
Client: ClientAudioPlayerSend Client Recebeu event! AudioPlayer Parent:Som1
Client: CLIENT: DEBUG 1
Client: CLIENT: DEBUG 2
Client: ClientAudioPlayerSend Client Recebeu event! AudioPlayer Parent:Som1
Client: CLIENT: DEBUG 1
Client: CLIENT: DEBUG 2

As you can see this is a very strange behaviour of this script.

Hello!
Are you sure that the client script does not have a second identical instance that can listen to this remote? If this is fine, analyze the calls of your module:ServerToClientManageSound function. Let me know if you have any more information on this!

I don’t know the structure of your system, but I can assume that there is a problem with calling that function.

I get this all the time.

You can fix it by adding a true/false toggle to your script. Like so:

local CanManageSound = true

function module:ServerToClientManageSound(PlayerAlvo:Player, AudioPlayer:AudioPlayer)
	
	if CanManageSound  then
		CanManageSound  = false
		
		if PlayerAlvo ~= nil then
			print("Function module:ServerToClientManageSound")
			ClientAudioPlayerSend:FireClient(PlayerAlvo, AudioPlayer)
			print("DEBUG 1")
			if PlayerAlvo.Character.Som:GetAttribute("GerenciarVolumeLoop") == false then
				PlayerAlvo.Character.Som:SetAttribute("GerenciarVolumeLoop", true)
			end		
		end			
		
		task.wait()
		CanManageSound  = true
	end

end

Even doing that its printing 2 times.

This Local Script is inside StarterPlayerCharacter. There is a possibility that the game is creating 2 characters and then having this script 2 times ?

I did a quick test to double check the functions you are using, it is here:

Test.rbxl (85.3 KB)

It is setup with a Script > Module > LocalScript (inside StarterCharacter).

It works without the double firing issue.

So, I am wondering about the script you have that controls the module. Can you show the relevant part of that script?

I found that my script clones my character when i enter the game. I think that is duplicating script. I changed to PlayerScripts instead CharacterScripts and solved the issue

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