Hi all. How would I make area music which is constantly playing and can only be heard in that specific area?
Thanks.
PS: So when the player enters that area it doesn’t restart the music.
This nifty data type can be used to detect a specific Region (Or specific area inside the workspace), you can use this by checking the Minimum & Maximum Sizes you want the Region to first start out from
Supposedly the easier way would be to reference invisible parts so that you can get their Part Sizes & multiply them to get their sizes
local RegionPart = workspace.RegionPart
local MinSize = RegionPart.Position - (RegionPart.Size * 0.5)
local MaxSize = RegionPart.Position + (RegionPart.Size * 0.5)
local Region = Region3.new(MinSize, MaxSize)
The next thing we’d want to do, is call Workspace:FindPartsInRegion3 which would return back a table of all the Parts it’s detecting, and we can encase this in a loop which would frequently check if a Player is near that specific RegionPart we recently defined (Keeping in mind you’d need to make this a LocalScript inside StarterPlayerScripts if you want it to change for individual players)
There are 3 parameters to keep in mind:
-
Parameter 1: The Region we want to search for
-
Parameter 2: The Part (And it’s descendants) to ignore
-
Parameter 3: The max amount of parts the Region can detect
local RunService = game:GetService("RunService")
local Sound = workspace --Insert your sound object here
RunService.RenderStepped:Connect(function()
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, math.huge)
for _, Part in pairs(Parts) do
local PlayerCheck = game.Players:GetPlayerFromCharacter(Part.Parent)
if PlayerCheck and PlayerCheck == YourPlayer then
Sound.Volume = 0.5
else
Sound.Volume = 0
end
end
end)
You’ll have to play the Sound server-sided, but affect it’s Volume property client-sided
Ok I’ve done this:
local RegionPart = game.Workspace:WaitForChild("Area1")
local MinSize = RegionPart.Position - (RegionPart.Size * 0.5)
local MaxSize = RegionPart.Position + (RegionPart.Size * 0.5)
local Region = Region3.new(MinSize, MaxSize)
local RunService = game:GetService("RunService")
local Sound = game.Workspace.Area1.Folder.Lobby --Insert your sound object here
RunService.RenderStepped:Connect(function()
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, math.huge)
for _, Part in pairs(Parts) do
local PlayerCheck = game.Players:GetPlayerFromCharacter(Part.Parent)
if PlayerCheck and PlayerCheck == YourPlayer then
Sound.Volume = 0.5
else
Sound.Volume = 0
end
end
end)
What do I put in “YourPlayer”?
I forgot to create a YourPlayer variable whoops LOL
So just for clarification, this script would need to be a LocalScript in order for it to work & you’d need to put it in StarterPlayerScripts
Try this and see what happens:
local YourPlayer = game.Players.LocalPlayer
local RegionPart = game.Workspace:WaitForChild("Area1")
local MinSize = RegionPart.Position - (RegionPart.Size * 0.5)
local MaxSize = RegionPart.Position + (RegionPart.Size * 0.5)
local Region = Region3.new(MinSize, MaxSize)
local RunService = game:GetService("RunService")
local Sound = game.Workspace.Area1.Folder.Lobby --Insert your sound object here
RunService.RenderStepped:Connect(function()
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, math.huge)
for _, Part in pairs(Parts) do
local PlayerCheck = game.Players:GetPlayerFromCharacter(Part.Parent)
if PlayerCheck and PlayerCheck == YourPlayer then
Sound.Volume = 0.5
else
Sound.Volume = 0
end
end
end)
It doesn’t work unfortunately. It makes a weird flickering noise.
Any idea why this is occurring?
What do you mean by flickering? Like is the sound’s volume going up and down?
No like it plays .1 seconds of the song then turns off for a bit. Repeat.
robloxapp-20210607-1342553.wmv (2.1 MB)
Video of it happening
Oh I think I see the issue
If your SoundPart is touching any other parts, then it would detect that as a non-Player which would result the Volume setting as 0, so it keeps repeating & looping through that I believe so we’d need to adjust the conditional check for the player detection
local YourPlayer = game.Players.LocalPlayer
local Character = YourPlayer.Character or YourPlayer.CharacterAdded:Wait()
local Torso = Character:WaitForChild("Torso")
local RegionPart = game.Workspace:WaitForChild("Area1")
local MinSize = RegionPart.Position - (RegionPart.Size * 0.5)
local MaxSize = RegionPart.Position + (RegionPart.Size * 0.5)
local Region = Region3.new(MinSize, MaxSize)
local RunService = game:GetService("RunService")
local Sound = game.Workspace.Area1.Folder.Lobby --Insert your sound object here
RunService.RenderStepped:Connect(function()
local Parts = workspace:FindPartsInRegion3(Region, RegionPart, math.huge)
local PlayerSearch = table.find(Parts, Torso)
if PlayerSearch then
Sound.Volume = 0.5
else
Sound.Volume = 0
end
end)
I’m unsure if this would work or not
this one did not work I’m afraid
I think the issue is that you’re literally playing the Sound over and over again, so it’s resulting as it playing from the beginning multiple times
Just remove that Sound:Play() line, you don’t need that
ALSO THAT’S LOUD FOR A VOLUME SETTING I DON’T THINK IT NEEDS TO BE THAT LOUD
still doesn’t work, what should I do?
Wait are you in Team Create or something-
Did you make sure to at least commit the Scripts inside the Drafts tab & referenced your Area Part, and Sound…?
yep, of course. I think I did it right.
Not sure why it isn’t working for you, maybe you can get a reference out of this cause I know this one works fine when you’re near the Area and you start to leave it:
SoundAreaTest.rbxl (29.3 KB)
