Im working on my own game where i want to add different Music in different Areas. But the Problem is that every help that i got from the Internet isnt helping. I tried making a brick which below the map and Plays the Music. But then there is one Problem. If a Player goes away from the Part, the Music gets quiter and if you go to an other Area, you still hear the Music from the other Areas. I just dont want to split every Area and Change the Volume of the Music. I want something like a brick which is Invisable. A Brick which Plays Music when the Player touches it for the first time. And if People touch an other Brick the Music will Change. Can anyone help me out with it ?
So you want the music to be played locally for just that player when they touch one Part, and when they touch a different Part then the music changes?
Do you want it to change to a certain song with that Part, or a random song from a list of songs?
So i have 2 different Rooms. A starting room and a small obstacle Course room. I want to add 2 different bricks which Play different Music. Like lets say someone joined the game. They start on the first checkpoint. An invisable brick which is covering the Ground will Play a Music after the Player touches it. If the Player teleports to the small obstacle room, the recent Music will get turned off and the Ground of the small obstacle Course Plays the Music for this area.
So yes. I want two different bricks which are invisable and Play a Music which i choose to Play when they get touched.
Im not that good at Scripting so i dont really know what you mean with inserting a touched trigger. I mean when i added this script and started the game it showed a red button which i could press. When i stopped test playing the red part disappeared. I added this script to an part and called ot MusicBox but the script ignored it.
I wouldn’t use a brick. Insert both sounds into SoundService. When a player joins, have a local script in their PlayerScripts play the first song. When they reach a 2nd area, have the server send over a RemoteEvent. Have the client stop the first song and start playing the 2nd song when the client receives the RemoteEvent.
Edit: I should add that another issue with bricks playing sound is that if they have surround sound, or headphones, 2 speakers, anything that uses spatial recognition, the sound will come out of different speakers depending on which way your camera is orientated.
I’ll try my best, I’ve never been a great teacher.
The first thing you’re going to want to do is to add your sounds into SoundService. Name one sound “Sound1” and the other one for Room 2 “Sound2”.
Now add a RemoteEvent into ReplicatedStorage. Title it “SoundEvent”. From here, insert a brick where the first room meets the 2nd room, so when they cross into the 2nd room they touch the brick. Make it’s transparency 1, CanCollide false, and make sure that players can’t accidentally pass by it without touching it.
Insert a script into the brick. You’re going to want to set the code in the script to this:
local players = game:GetService("Players")
script.Parent.Touched:Connect(function(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
local char = part.Parent
local target = players:GetPlayerFromCharacter(char)
game.ReplicatedStorage.SoundEvent:FireClient(target)
end
end)
Now the game detects when the player crosses into the 2nd room. Now we need to change the song. Place a localscript in StarterPlayerScripts (under StarterPlayer in explorer) and make this the code:
This is the Starting Room. I want that one Music Plays in this room. You see a large Door with a small sign next to it. This is the first Obstacle Course.
This is how it Looks like when you walk through the door. This room should not Play the Music from the beginning and should stay quiet. At the end of this room is a small red Portal which teleports the Player into the first obstacle Course.
This is the first obstacle Course. There should Play a new Music until the Player hits the teleporter at the end and gets back to the beginning Area.
I hope These Pictures are helping to understand it.
Oki i will try to explain it as detailed as possible. You see 3 Areas. Beginning Room. Teleport Room and the Obstacle Course Room. Beginning Room and Obstacle Room Need to Play their own theme while teleport room stays silent.
So this is your problem, a sound emitter emits sound in a circle radius. You may want to develop your map around this circle. If you don’t want to adjust your map, you can look into having the sounds be muted from the client when you move to a different area
But there is another Problem. If a brick has that Music inside of it. The Music gets louder if you are in the Center of the brick. So if you stand in a Corner then the Music would be a Little bit quiet and if you near the Center it will get louder. I once had that Problem with one of my older games
Can’t really join game rn, however I can write some code up later. Just try to explain what you are trying to get as best as possible here. My suggestion currently would to maybe use region3 WorldRoot | Documentation - Roblox Creator Hub
Oof im trying to send a Video but it isnt working. So if i put a large brick on the Ground and stay on the Corner, the Music is quiet. But if i walk to the Center of the Brick the Music gets louder. But i want that the whole brick or room has the same Volume and not getting quieter even tho im still on the brick and just walked a bit away from the Center of it. I dont know. Maybe i have to Change the radius of the Music but then it would take so Long to move the camera in roblox Studio from area 1 to area 2
Ok, here is the code I created, I have created notes so you can take this and maybe modify it to your needs
First this is how I set everything up
I made the zones not fully transparent so you could see them
You can download the place here MusicPlaying.rbxl (21.1 KB)
or copy the source code and copy the setup
source code
local whiteList = {} -- Whitelist for zone
if not(game.ReplicatedStorage:FindFirstChild('MusicEvent')) then --Checks if there is an event, otherwise it creates one
Instance.new("RemoteEvent",game.ReplicatedStorage).Name = 'MusicEvent'
end
local event = game.ReplicatedStorage:FindFirstChild('MusicEvent') --Defining event
game.Players.PlayerAdded:Connect(function(player) --Fires when the player is added
player.CharacterAdded:Connect(function(char) --Fires when the character is added
table.insert(whiteList,char) --Adding the character to the white list
end)
player.CharacterRemoving:Connect(function(char) --Fires when the character is benig removed
table.remove(whiteList,table.find(whiteList,char)) --Removing the character from the white list (if the player dies or leaves)
end)
end)
while true do --Loop
for i,v in ipairs(game.Workspace.MusicZones:GetChildren()) do -- Gets all the music Zones
local min = v.Position - v.Size*.5 -- Getting the size of the zone
local max = v.Position + v.Size*.5 -- Getting the size of the zone
local parts = workspace:FindPartsInRegion3WithWhiteList(Region3.new(min,max),whiteList,100)
-- That gets the parts in the zone
for h,d in ipairs(parts) do -- Going through each part
if d.Name == 'HumanoidRootPart' and game.Players:GetPlayerFromCharacter(d.Parent) and v:FindFirstChild('Music') then
-- Checking if the name is HRP and the player is in the game and there is a music ID
event:FireClient(game.Players:GetPlayerFromCharacter(d.Parent),v:FindFirstChild('Music').Value)
-- Sends the music ID to the player
end
end
end
wait(1) -- Waits one second before doing the loop again
end
local event = game.ReplicatedStorage:WaitForChild('MusicEvent')
-- Defines event
event.OnClientEvent:Connect(function(musicId) --Fires when the event is called
if script.Parent.Music.SoundId ~= musicId then
script.Parent.Music.SoundId = musicId
print('now playing '..musicId)
script.Parent:Play()
-- Plays the new sound
else
print('still playing '..musicId)
--Still playing the old sound
end
end)
Make sure you copy everything over, and to change the music, change the Music Value under the zone part. Good luck on your project!