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)
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.
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.