Hey guys! I'm working on a new project for a guy, and he wants to have area based sound, but with a way for there to be some sort of a boombox. This question will mainly be asking about ideas and optional solutions to this potentially complex issue.
The first thing I had to address was the fact that sounds play on every client if they are played from one client. Thankfully, there's this simple solution:
local sound_service = game:GetService("SoundService")
sound_service.RespectFilteringEnabled = true
Next, I decided every sound would be client side except for boombox sounds. First, I ran into the problem of deciding how to do areas. Region3 is an idea, but I figured it'd be more ideal to just have transparent and non-cancollide parts as the areas and detect when a touch began and ended on the client. Basically, the idea is that there will be a table with whatever elements of the player that have touched the sound area. Then, when the TouchEnded event fires, I'll remove the associated object from the table. This isn't as simple as Region3s, but it makes it easier on the dev that I'm working for to maneuver the areas around. If you have any suggestions on how to make this better, just let me know.
Anyway, I was wondering if there was an efficient way of detecting if a server side (aka a boombox) sound gets in range. I could fire a remote to every client telling them when a boombox turns on so that they can specifically check to see if that player gets in range, but that still seems rather inefficient, especially if there are multiple people with boomboxes on. Is there an event to tell me if a player is in range of a sound (I certainly couldn't find one)? If I wanted to just do the most inefficient method, then I could do something like this:
local players = game:GetService("Players")
local music_play_distance = 1000
while true do
local player_array = players:GetPlayers()
for i = 1, #player_array do
local player_to_check = player_array[i]
if player_to_check ~= player then
local boom_box_is_active = player:FindFirstChild("Boom_Box_Is_Active")
if boom_box_is_active and boom_box_is_active.Value then
local character = player_to_check.Character or player_to_check.PlayerAdded:Wait()
local root_part = character:WaitForChild("HumanoidRootPart")
if player:DistanceFromCharacter(root_part.Position) < music_play_distance then
-- function to fade out area music is called
end
end
end
end
wait(0.5)
end
but again, I feel like there's a better solution. Any suggestions are immensely appreciated.
Finally, I come to one of the two main problems I encountered when working on this project (the first being the detection of sound / when to play what sound). Sounds don't start immediately when you call the Play method on them even if their IsLoaded property is set to true. You can read more about that here. The time delay before a song plays appears to be arbitrary, so merging songs into other songs seems to be nigh on impossible, but games like MinersHaven seem to have pulled it off. Songs should be able to be easily merged into each other as a player moves around the map and perhaps encounters someone with a boombox.
Any recommendations/ideas/suggestions are immensely appreciated. Thank you for taking the time to read this. If you have any additional questions/comments, please post them in the comments below.

1 comment
MAGNITUDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE