You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Utilizing region3 to enable the player to listen to a server-side music playlist when inside the said region.
-
What is the issue? Include screenshots / videos if possible!
I currently have regions set up to work with a client-side music player, but I’m so lost on trying to set it up to work with one particular region connecting to a server side script that handles its own playlist. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have a somewhat approach to this with:
local function SetPlayerRegion() --check if in region
local char = LocalPlayer.Character
if char then
local inRegion = false
for regionName, region3 in pairs(REGIONS) do
local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(region3, {char})
--print(partsInRegion)
if #partsInRegion > 0 then
inRegion = true
if ClientMusicZone.PlayerRegion ~= regionName then --check if changed region
ChangeRegion(regionName)
if regionName ~= "Club" then
REMOTE:FireServer(char, ServerPlaylist)
end
end
break
else
end
wait(0.5) --makes the microprofiler happier
end
if not inRegion and ClientMusicZone.PlayerRegion then
ChangeRegion(nil)
end
end
end
My issue with this is i’m unsure of what to actually set my parameters for firing the remote.
This is just example code of a server-side script I found for mostly testing purposes before actually editing the script to do what I actually want it to do, but I’ve found it difficult to connect the two.
Ideally since music is being handled by the server, shouldn’t it always be set to volume = 0 for a client not within the region and volume increased when region is entered?
local MODE = "random"
local MarketplaceService = game:GetService("MarketplaceService")
local audio = Instance.new("Sound")
audio.Name = "MusicAudio"
audio.Parent = workspace
local remote = game.ReplicatedStorage.Remotes.MusicZoneRemote
local songs = require(script.Songs)
local rand = Random.new(tick())
local currentIndex = 0
local function pickSong()
local i
if MODE == "cycle" then
if currentIndex == #songs then
currentIndex = 1
else
currentIndex = currentIndex + 1
end
i = currentIndex
else
i = rand:NextInteger(1, #songs)
end
return songs[i]
end
local nowPlaying = ""
local function getSongName(id)
local data = MarketplaceService:GetProductInfo(id)
nowPlaying = data.Name
return data.Name
end
remote.OnServerEvent:Connect(function(player,nowPlaying)
remote:FireClient(player, nowPlaying)
end)
while true do
local song = pickSong()
print("Now Playing:", song)
remote:FireAllClients(getSongName(song))
audio.SoundId = "rbxassetid://" .. song
audio.TimePosition=0
audio:Play()
audio.Ended:Wait()
audio:Stop()
end
Side note for the server script, the playlist for this is handled within a module script.
My main hurdle is just getting them to connect to each other. I should be able to figure out the rest as far as modifying the code to behave with my UI and such as needed.