Need help with region music!

I watched this video: How to Make AREA-ONLY MUSIC | HowToRoblox - YouTube
-In the video, he taught me how to make a region music system (you can watch it for more information).
-The reason why I’m here is because I want to make it server-sided, I will try my best to describe it.
-In the video, if Player1 walk in the area, he will hear the music that only play for him, that’s mean if Player2 walk in, he will hear the music that play again for him. Only Player2 will listen the reseted-music, Player1 continue listen to his own track. And if players walk out, and if they walk in again, the music will reset.
-So the things I want is: If Player1(the first player) walk in, he trigger the music and if Player2(second player) walk in, he will listen to the same track as Player1, “Player2 won’t listen to the music from start”. And if the players walk out, the music won’t stop, it will continue play in the area, if you walk in again, you will continue listen to it.
this is his local script, placed in StarterCharacterScript.

local sound = Instance.new("Sound", script)
sound.Looped = true


local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")


local areasGroup = workspace:WaitForChild("Areas")

local currentArea = nil


game:GetService("RunService").Heartbeat:Connect(function()
	
	
	local raycast = Ray.new(hrp.Position, hrp.CFrame.UpVector * -1000)
	
	local part = workspace:FindPartOnRayWithWhitelist(raycast, {areasGroup})
	
	
	if part and part.Parent == areasGroup then
		
		if part ~= currentArea then
			
			currentArea = part
			
			sound.SoundId = currentArea.Music.SoundId
			sound:Play()
		end	
		
	else
		
		currentArea = nil
		sound:Stop()
	end
end)
1 Like

Do it locally, it’s better based on your needs.

2 Likes

Play all the sounds inside a server script in ServerScriptService:

local Areas = workspace:WaitForChild("Areas")

for i, area in pairs(Areas) do 
	local Sound = area:WaitForChild("Music", 5)
	if not Sound then continue end 
	Sound.Looped = true 
	Sound.Volume = 0
	Sound:Play()
end

and instead of playing the sound on the client, just set the volume, so in your client script, replace sound:Play() with sound.Volume = 0.5 and sound:Stop() with sound.Volume = 0.

1 Like

so I need to change some lines in the local script and make a new server script and paste your code in right?

1 Like
local rs = game:GetService("RunService")
local plrs = game:GetService("Players")

local areas = workspace:WaitForChild("Areas"):GetChildren()
local currentArea = nil

plrs.PlayerAdded:Connect(function(player)
	local char = player.Char or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	rs.Heartbeat:Connect(function()
		
		for _, area in ipairs(areas) do 
			local Sound = area:WaitForChild("Sound", 5)
			if not Sound then
				Sound = Instance.new("Sound")
				Sound.Parent = area
			end
			Sound.SoundId = 0
			Sound.Looped = true 
			Sound.Volume = 0
			Sound:Play()
		end
	end)
end)

Probably something like this, needs to changing to fit your needs however.

Try using the ZonePlus v3 module to effectively see if a player is in a region.

I believe I already have a script on that in one of my games, do you still need help if so I can help!

@TeemoHoang_2008
This is what I have for my game it’s a local script in StarterPlayerScripts
image
And put a sound group in SoundService and add the music
And in workspace put a folder named: SoundRegions with the parts:
image

local Folder = game.Workspace.SoundRegions
local Event = game.ReplicatedStorage.ClientEvent.SoundEvent
local Sounds = {
	["S1"] = game.SoundService.SoundGroup;
	["S2"] = game.SoundService.SoundGroup;
	["S3"] = game.SoundService.SoundGroup;
	["S4"] = game.SoundService.SoundGroup;
	["S5"] = game.SoundService.SoundGroup;
	["S6"] = game.SoundService.SoundGroup;
}
local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()

for _,v in ipairs(Folder:GetChildren()) do
	print("w")
	if v.ClassName == "Part" then
		v.Touched:Connect(function(Hit)
			if Character == Hit.Parent then 
				if v.Name == "SoundRegionStage1" then
				
					----------------
					Sounds.S1:Play()
					Sounds.S1.Looped = true
				elseif v.Name == "SoundRegionStage2" then
					
					----------------
					Sounds.S2:Play()
					Sounds.S2.Looped = true
				elseif v.Name == "SoundRegionStage3" then
					
					----------------
					Sounds.S3:Play()
					Sounds.S3.Looped = true
				elseif v.Name == "SoundRegionStage4" then
					
					----------------
					Sounds.S4:Play()
					Sounds.S4.Looped = true
				elseif v.Name == "SoundRegionStage5" then
					
					----------------
					Sounds.S5:Play()
					Sounds.S5.Looped = true
				elseif v.Name == "SoundRegionStage6" then
					----------------
					Sounds.S6:Play()
					Sounds.S6.Looped = true
				end
           end
		end)
		v.TouchEnded:Connect(function()
			Sounds.S1:Stop()
			Sounds.S2:Stop()
			Sounds.S3:Stop()
			Sounds.S4:Stop()
			Sounds.S5:Stop()
			Sounds.S6:Stop()
		end)
	 end
 end

If you need help setting it up reply back.
(In the Sounds Table add the sounds you want.)

1 Like

Thanks for all the replies, I will try everything and will reply back soon.