Radio messages sending twice

Hello,

I have this radio system, however when a message is sent 9/10 times it sends 2 messages instead of 1. I’m not sure what’s causing this. Does anyone have any advice on how to fix this or a work around to prevent the same message being sent twice.

Thanks,

Server Script (In serverscriptservice)

clientsend.OnServerEvent:Connect(function(Player, msg, fireablevalue)
allclients:FireAllClients(Player, msg, fireablevalue)
end)

Local Script (In radio tool/gui)

player.Chatted:Connect(function(msg)
	if radioon.Value == true then
		if table.find(radiosettings.whitelistedteams, player.Team.Name) then
			local fireablevalue = channel.Value
			clientsend:FireServer(msg, fireablevalue)
			

			
		end
	end
	
end)


allclients.OnClientEvent:Connect(function(Player, msg, fireablevalue)
	local replication = game:GetService("ReplicatedStorage").RadioGUIReplicated.Message:Clone()
	if fireablevalue == "Channel1" then
		replication.Parent = gui.MainFrame.GeneralScrollingFrame
		replication.TextLabel.Text = Player.Name..":" .. msg
		-- EDIT THE NAMETAG LABELS!!!!! xoxox -emily
		if string.sub(msg, 1, 4) == "/fd " and Root.nametags.Frame.TextLabel.Text == "Captain" or Root.nametags.Frame.TextLabel.Text == "First Officer" then
			replication.BackgroundColor3 = Color3.new(0.666667, 0, 0)
			replication.TextLabel.TextColor3 = Color3.new(1, 1, 1)
			Sounds.FDComm:Play()
		elseif string.sub(msg, 1, 4) == "/cc " and Root.nametags.Frame.TextLabel.Text == "Cabin Crew" or Root.nametags.Frame.TextLabel.Text == "Cabin Manager" then
			replication.BackgroundColor3 = Color3.new(0.666667, 0, 0)
			replication.TextLabel.TextColor3 = Color3.new(1, 1, 1)
			Sounds.CrewComm:Play()
		end
		
		gui.MainFrame.GeneralScrollingFrame.CanvasPosition = Vector2.new(0, gui.MainFrame.GeneralScrollingFrame.AbsoluteCanvasSize.Y)
	end
end)
1 Like

Are you using unreliable remote events or regular remote events, as I can see if one event were to misfire, causing sort of a queue?

Regular Remote Events. Not I’ve ever used the Unreliable ones.

I recommend parenting the server script to ServerScriptService instead of ReplicatedStorage. Instances in ReplicatedStorage exist both for the client and the server so it might be causing you the problem. You’ll need to update any variables inside of the script that depend on the parent being ReplicatedStorage to reflect the change to ServerScriptService though else you’ll experience errors

Ah yeah sorry I meant serverscriptservice not replicated. The remotes are all in replicated storage.

1 Like

I read your scripts and there doesn’t seem to be anything that could cause the message to be repeated. When you said the message is sent twice 9/10 times, does it work correctly always at the first time you send a message then start to repeat? If yes, than I suspect the OnServerEvent connection is being created inside of another connection which is causing a memory leak and your message to be sent twice after the first time

With just the 1 client / player with the radio tool it works as intended fine.

But with 2 or more clients with the radio tool it duplicates the messages 9/10 times.

Are the scripts provided complete or are they snippets of the whole script? If they are snippets, then we’ll most likely need to see the whole script to identify the problem

Edit: @MissBasicallySoft as a test you could also add a print(true) statement inside the OnServerEvent to see if it’s receiving the message twice, and then do the same test in the OnClientEvent and see if true is being printed twice in succession. The statement should be at the top so that the rest of the function doesn’t interfere with the result

It’s some of the code. If you want to add me on discord I can send the full scripts to look at if that helps.

I added those true statements in though. When a single client it prints true once (one in client and one in server)

When someone else is in the server it fires twice.

I don’t have a Discord account unfortunately

Which print statement is outputting twice, the one on the server or the client?

There is a bug causing player.Chatted to unexpectedly fire twice. It hasn’t been patched in a while. For now the only way you could fix this is adding a debounce.

Both of them are sending twice.

I tried to test your suggestion and I found something quite odd because for me player.Chatted only works when used in a server script so I don’t know how it’s working in a LocalScript for @MsBasicallySoft. I’m using TextChatService instead of legacy chat though so that could be the cause

Since player.Chatted works on the server as well you can technically eliminate the clientsend RemoteEvent and do something like this on the server:

local Players = game:GetService("Players")

local allclients = game:GetService("ReplicatedStorage").allclients -- Change this to match the real name

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if radioon == true
		and table.find(radiosettings.whitelistedteams, player.Team.Name)
		then
			local fireablevalue = channel.Value

			allclients:FireAllClients(player, msg, fireablevalue)
		end
	end)
end)