There’s an option in my game to enable and disable music via a localscript, however it seems like despite it being a localscript, the music will play or stop for everyone in the server. There are other scripts set up to save whatever option the player chooses and to then load it in through a RemoteEvent, but even then the only time the sound gets turned on/ off is through the localscript.
This is the localscript that deals with playing the music:
rs = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:Connect(function()
if workspace.TGS.Playing == false then
script.Parent.Text = "Background Music: ON"
script.Parent.BackgroundColor3 = Color3.fromRGB(20,141,255)
rs.Events.SettingChoice:FireServer("Music", true)
workspace.TGS:Play()
elseif workspace.TGS.Playing == true then
script.Parent.Text = "Background Music: OFF"
script.Parent.BackgroundColor3 = Color3.fromRGB(203, 6, 36)
rs.Events.SettingChoice:FireServer("Music", false)
workspace.TGS:Stop()
end
end)
-- this loads the saved option when the player first joins
rs.Events.SettingChoice.OnClientEvent:Connect(function(setting, option)
if setting == "Music" then
if option == true then
workspace.TGS:Play()
script.Parent.Text = "Background Music: ON"
script.Parent.BackgroundColor3 = Color3.fromRGB(20,141,255)
else
workspace.TGS:Stop()
script.Parent.Text = "Background Music: OFF"
script.Parent.BackgroundColor3 = Color3.fromRGB(203, 6, 36)
end
end
end)
This is the code for saving the options to DataStore, in ServerScriptService:
local DSS2 = require(1936396537)
game.ReplicatedStorage.Events.SettingChoice.OnServerEvent:Connect(function(p, setting, option)
if setting == "Music" then
if option == true then
local current_setting = DSS2("MusicSetting", p)
current_setting:Set(true)
else
local current_setting = DSS2("MusicSetting", p)
current_setting:Set(false)
end
elseif setting == "Volume" then
local current_setting = DSS2("MusicVolume", p)
current_setting:Set(option)
elseif setting == "ScrollSound" then
if option == true then
local current_setting = DSS2("ScrollSound", p)
current_setting:Set(true)
else
local current_setting = DSS2("ScrollSound", p)
current_setting:Set(false)
end
end
end)
Finally, this is the code that loads the saved option upon joining the game, also in ServerScriptService. This gets picked up by the last bit of code in the first script, which I left a comment about.
local DSS2 = require(1936396537)
rs = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(p)
p:WaitForChild("Settings")
workspace:WaitForChild(p.Name)
wait(2)
if p.Settings.MusicOn.Value == true then
rs.Events.SettingChoice:FireClient(p, "Music", true)
else
rs.Events.SettingChoice:FireClient(p, "Music", false)
end
wait()
if p.Settings.ScrollOn.Value == true then
rs.Events.SettingChoice:FireClient(p, "ScrollSound", true)
else
rs.Events.SettingChoice:FireClient(p, "ScrollSound", false)
end
wait()
rs.Events.SettingChoice:FireClient(p, "Volume", p.Settings.Volume.Value)
end)
But as stated before, all of the code that deals with actually playing the music is on a localscript. The volume option also seems to be affected by this bug. However, the other settings that are also controlled on the client are not affected.