Area Music Player Script! [Open Source]

Better way of putting it, sound regions. This is pretty nice, well done.

Does this support non-rectangular music areas?
Can I use Unions or spheres?

Woah that death sound was super cool. How did you do that?

it is from the module script that is the parent of the script that has all of the sounds and main code

@Wertyhappy27
You can’t require a LocalScript, only ModuleScript.


@dispeller
Nope, but you can use this:

local function IsPointInPart_Fn(Point, Part) -- Cylinder
    local relPos = Part.CFrame:PointToObjectSpace(Point)
    local distFromCenter = Vector2_New(relPos.Y, relPos.Z).Magnitude
    local radius = Part.Size.Y*.5
    return Math_Abs(relPos.X) < Part.Size.X*.5 and distFromCenter < radius
end

credits to my mentor


You could also use GetTouchingParts.

Personally, the first time I made an area music system, I used Region3.

I looped this every 5 seconds. That way, each piece of music played for at least 5 seconds. Kinda prevents breaking immersion
function UpdateRegion()

	local inRegion = false
	
	for i,v in pairs(game.ReplicatedStorage.BorderBlocks:GetChildren()) do
	
		local min = v.Position - (0.5 * v.Size)
		local max = v.Position + (0.5 * v.Size)
		local region = Region3.new(min, max)
		local whitelist = {Player.Character}
		local parts = workspace:FindPartsInRegion3WithWhiteList(region,
														whitelist, 100)
		--warn(#parts)
		for partIndex, part in pairs(parts) do
			--print('PART NAME!'..v.Name)
			if part.Parent == Player.Character then
				inRegion = true
				if regionCurrentlyInside ~= v.Name then
					regionCurrentlyInside = v.Name
					print'CHANGED REGION!'
				end
			end
			
		end
	
	end
	
	if not inRegion then
		if regionCurrentlyInside ~= 'Outside' then
			regionCurrentlyInside = 'Outside'
			print'went outside'
		end
	end

end

There was also this module called Zone+ that might be useful.

Lots of ways to do this.
Cool module!

I noticed that in post #6

I also mentioned that using Region3 is tedious and not Non-Programmer friendly, you can refer back to post #6 for more details.

indeed there are multiple ways of achieving the same thing~


1 Like

If region 3 is “tedious”, isn’t it your job to make it easier? I wouldn’t recommend this to anyone, .touched event is unreliable.

If I were you, I would use region 3 and get players to define zones using parts, then calculate region3 zone for them. Not so hard is it?

Despite the comments about using region 3 and about using TouchedEvent not being reliable, I thank you for this resource that can improve my scripting abilities, continue doing what you do best :pray:.

Also is there a way to turn this into a music player where you can just insert the song id and play different types of music such as a party setting etc and how would you go about doing that?

1 Like

I added it how you had it set up in your game, i have no idea what is wrong

This is so cool! Thx bro! I like this :slight_smile:

1 Like

Hey man, wonderful script. However it seems there is a problem for me while using it. Whenever a character dies, and respawns, the music stops. It used to work just fine, but after I changed the volume in the Module Script it seemed to have messed the script up? Idrk what went wrong.
Here’s the script

1 Like

This did the trick for me, there’s a mistake in the module:

Replace the Character_Added function with:

local function Character_Added(Character)
	if (not cache[Character]) then
		cache[Character] = tick()
		Cha = Character; Hum = Cha:WaitForChild('Humanoid'); RootPart = Cha:WaitForChild("HumanoidRootPart")
		HumDied_Connection = Hum.Died:Connect(Humanoid_Died)
	end
end
3 Likes

Yep, also found out it was because I altered the respawn time from 5, to 1 second. Idk, if putting this in would fix, but at least you found something wrong, and fixed it :+1:

Thanks alot, I’d love to use this in my game!

Keep it up! Love this resource. I’m probably gonna use it in my game.

Thanks, this is very helpful! Definitely helps add some atmosphere.

Could you add a few features,

  • mute button (cant hear music)
  • multiple tracks for an area, play randomly
  • Gui on the screen that says what is playing, you can put a value in the music object that has the title and artist, if nothing is there, then it doesn’t display.

I managed to glitch it, if you use MoveTo() on character that is inside the zone, and the HumanoidRootPart is Anchored, the music still plays. Please fix

How can I make this useable with unions? I have areas that overlap and was wondering how I can work around the music going at the same time.