RemoteEvent connection is not working

I am making a script for a simple radio system within my game. it works useing by sending a message from the microphone by the players speach to a radio speaker where ChatService:Chat is used to display the message.

The problem lies in the radio script not connecting to the remote event when fired

Main script:

local Microphone = require(script.Microphone)
local Radio = require(script.Radio)

for i,v in pairs(workspace:GetChildren()) do
	if v.Name == "RadioMicrophone" then
		Microphone.RadioMicrophone(v)
	end
end

for i,v in pairs(workspace:GetChildren()) do
	if v.Name == "Radio" then
		Radio.Stereo(v)
	end
end

Microphone Moduel Script

local module = {}

local ChatService = game:GetService("Chat")

module.RadioMicrophone = function(part)
	local switch = part.Switch.ProximityPrompt
	switch.Triggered:Connect(function(Player)
		print("switched")
		wait()
		if switch.ObjectText == "Start" then
			
			part.Light.Material = Enum.Material.Neon
			switch.ObjectText = "End"
			
			Player.Chatted:Connect(function(message)
				print(Player.Name .. ": " .. message)
				game.ReplicatedStorage.Radio.RadioBroadcast:FireAllClients(Player, message)
				print("fired")
			end)
			
		elseif switch.ObjectText == "End" then
			switch.ObjectText = "Start"
			part.Light.Material = Enum.Material.SmoothPlastic
		end

	end)
end

return module

radio script (the broken one)

local module = {}

local ChatService = game:GetService("Chat")

module.Stereo = function(part)
	print("waiting")
	wait()
	game.ReplicatedStorage.Radio.RadioBroadcast.OnServerEvent:Connect(function(player, message)
		print("connected")
		local formattedMessage = player.Name .. ": " .. message
		
		ChatService:Chat(part.Stereo, formattedMessage, Enum.ChatColor.Red)
	end)
end


return module

Scripts are all located under serverscriptservice. I have been attempting to debug this for over an hour 45 now any help would be greatly appriciated

1 Like

Are you sure the print("waiting") works?
And what’s the client script?

yes the (“waiting”) is printing but (“connected”) isn’t. there also isnt a need for a client script as I get the player through the proximityprompt

RemoteEvents are used to communicate between server and clients, if there’s no need for a client-script, then you shouldn’t use them.

More info about the server-client model and remote events:

how else do i communicate the infomation to the other script?

in the broken radio script you try to catch the event using OnServerEvent, instead use OnClientEvent

You can require the radio script and call the stereo method.
(Remove the event connection though.)

would it be possible to send it from the microphone script to a local script then into the radio script?

i’m not sure, but also another thing is you don’t have to specify ‘player’ argument when using FireAllClients. try removing it

That would be pretty pointless since there’s no need for a client in your script.
Use the method that I gave you.

I have just tried that and it came out with a nill

Require the radio script, and call the stereo method.
Here’s an example:

local radio = require(script.Parent.Radio)
radio.Stereo(part)

Make sure to remove the: game.ReplicatedStorage.Radio.RadioBroadcast.OnServerEvent:Connect(function(player, message) part.

I’m really stuggling with this i can’t find a way of doing this without one of the scripts breaking, the other script needs the context of the remote event to work as it dosent know who the player is or the message