So I’ve been looking around on how to play sound only to a local player–found multiple suggestions saying “place it in playergui” or soundservice. So I went ahead and used SoundService but I’m not sure if it is appropriate for what I am doing.
So basically I have it to where I will do fireclient remote to a local script. The local script determines whether to play lobby music or select game music, I have it to where the lobby music’s id will be randomized each time the remote is called and lobby music is determined to play.
Music:FireClient(player, map)
--FireClient, sends certain parameters that I will use (Is in a separate serverscript)
--LocalScript
Music.OnClientEvent:Connect(function(plr, map)
print(1) --prints were used for debugging
local Players = game:GetService("Players")
local player = Players.LocalPlayer
--obtaining localplayer, couldn't seem to use plr for bellow but regardless it works.
--I also have an outside local, that links to game.teams.lobbyteam
if player.Team==LobbyTeam then
local y=LobbyMusicIDs[math.random(#LobbyMusicIDs)]
local LobbyMusic=SoundService.MusicFolder.LobbyMusic
LobbyMusic.SoundId=string.format("rbxassetid://%d", LobbyMusicIDs[math.random(#LobbyMusicIDs)])
print(LobbyMusic.SoundId)
Music1:Stop()
SoundService:PlayLocalSound(LobbyMusic)
print(3)
end
if player.Team~=LobbyTeam and map=="Swamp" then
--Specific music plays for certain map and if not lobbyteam i.e. in actual match
LobbyMusic:Stop()
SoundService:PlayLocalSound(Music1)
end
print(2)
end)
--The remote calls everytime player respawns.
My question is, is this the best way to go? I feel like changing the id could affect other people (or even stopping the sound too) as well since there’s only one instance of the sound which is in SoundService. I think I should put the folder inside startergui (playergui, which creates multiple instances for each player!) but what are your thoughts?
(Also if it isnt clear, I’m trying to have it to where lobby people listen to lobby music, in-match players play music associated with map)