Hello! I am trying to make different music play in different maps/lobby. Players in the lobby will hear different music than those in the map which is also in the same workspace. The maps clone from server storage and destroy when they are not in use.
I have read that onTouched should not be used as it is unreliable. Region3 (which I just heard of in the last few days) might work, but I can’t make a region3 from the map model.
How do I make different music play for different maps and the lobby?
How do I make a Region3 around a model?
Another note: if I just use a block around the model to “convert” to a Region3, it will fire onTouch events within the map that cause errors.
You can create new regions surrounding a map with two positions opposite each other on a cube. Just insert a part and cover the entire map with it and then do this to create the region based off of that parts positions:
local regionPart = game.Workspace.Part -- This is the part surrounding your map
local pos1, pos2 = (regionPart.Position - (regionPart.Size / 2)), (regionPart + (regionPart.Size / 2))
-- pos1 finds the bottom right corner position of the part and pos2 finds the top right corner position
local region = Region3.new(pos1, pos2) -- Now use these two positions to create the region based off of the part
Now you’ll have to do this every time you clone and spawn a map since you’re destroying the map along with the region part, but it shouldn’t be too bad. You’ll also need to make sure that you destroy the region itself so that you don’t have overlapping music.
Take a look at this video it should help a bit, I used that code excerpt from him. https://www.youtube.com/watch?v=qOhZi1jUEvI&t=1338s
He’ll show you towards the end how to create a region from a part like I showed above as well as how to detect a player within the region so you can make something happen such as play music. He sets the player on fire, but instead of that you would type in your music code.
You can also try making invisible regions or floors and raycasting to see if youre inside one of them