I have recently been looking for a way to make a radio with proximity chat support. An example of this would be where a user, who we’ll call Bob for now, equips the radio tool, enables proximity chat in-game, and can begin talking to other users with the radio equipped, and the other users can begin talking to Bob. I have tried SoundService’s SetListener, but can’t seem to get it working, if anyone has any ideas on how to do this, please let me know.
2 Likes
i need a system like this too for my backrooms unturned inspired game
Creating a radio with proximity chat support can be achieved by using RemoteEvents to communicate between the server and clients, along with the use of the SoundService. Here’s a basic outline of how you can implement this:
- Create a RemoteEvent in ReplicatedStorage named “RadioChatEvent”.
- In a ServerScript, handle player events, like equipping and unequipping the radio tool, enabling and disabling proximity chat, and broadcasting the radio chat.
- In a LocalScript within the radio tool, handle user input to enable/disable proximity chat and communicate with the server using the RemoteEvent.
- In another LocalScript, handle the radio chat reception by playing the received audio on the client side.
ServerScriptService:
-- ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RadioChatEvent = ReplicatedStorage:WaitForChild("RadioChatEvent")
RadioChatEvent.OnServerEvent:Connect(function(player, action, ...)
local args = {...}
if action == "StartProximityChat" then
-- Broadcast to other players with radio equipped
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
RadioChatEvent:FireClient(otherPlayer, "ReceiveProximityChat", player, args[1])
end
end
end
end)
And here’s an example of how to set up the client-side part:
-- LocalScript inside the Radio Tool
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RadioChatEvent = ReplicatedStorage:WaitForChild("RadioChatEvent")
local player = game.Players.LocalPlayer
local function startProximityChat()
-- This can be replaced with actual audio input
local exampleAudioData = "ExampleAudioData"
RadioChatEvent:FireServer("StartProximityChat", exampleAudioData)
end
-- Connect startProximityChat to user input (e.g., key press, UI button, etc.)
-- LocalScript to handle radio chat reception
RadioChatEvent.OnClientEvent:Connect(function(action, sender, audioData)
if action == "ReceiveProximityChat" then
-- Play received audioData using SoundService
-- Make sure the sound is only audible within a specific range, and adjust the volume accordingly
end
end)
You can use the Microphone API to get real-time microphone input on supported platforms. The example above is a basic outline, and you’ll need to adapt it to your specific use case, including error handling and additional features.
1 Like