How can I get a Settings GUI to save?

Hello! How can I make it when you disable a setting, for example, let’s say a Music setting, it save the next time you join so you don’t have to keep changing it. This could include other ones, but I only have a Music one right now. How can I do this? I know I can do it with a Datastore, but I am not really good at those.

Thanks! Any help will be appreciated!

2 Likes

There’s your answer.

When you’re saving a table inside the DataStore:SetAsync() or DataStore:UpdateAsync() function, you should include a table in it where the key is called Settings, then inside the value, you add another table and each element in it save your settings, for example it could be like SettingsGui.MuteSound.Value where Value is a data type data store can save. You get the ide.

2 Likes

The most practical and maybe easiest way to save a GUI (settings, preferences, etc) is to create values for each setting and save each if and once their value changes.

How to save a table of values:

Hope this helped! Good luck! :smiley:

3 Likes

You’d need to use a DataStore, do you have any code to work with?

1 Like

Not really, but here is the music thingy

script.Parent.MouseButton1Click:Connect(function()
	if game.SoundService.GameSound.Volume == 0.5 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
		
	else
		
			if game.SoundService.GameSound.Volume == 0 then
				game.SoundService.GameSound.Volume = 0.5
				script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
				script.Parent.Text = "On"
		end
	end
end)
2 Likes
script.Parent.MouseButton1Click:Connect(function()
	if game.SoundService.GameSound.Volume == 0.5 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
	elseif game.SoundService.GameSound.Volume == 0 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
	end
end)

How are songs being played? Also you should note that if the volume is not 0 or 0.5 then the entire function is ignored.

2 Likes

I know that, the volume for the music is 0.5 lol. It’s being played in SoundService?

I mean, where’s the script which allows players to enter an audio ID for it to be played?

What? No one said that they could do that. It’s just an audio inside SoundService?.. What are you talking about?

Oh, just a volume setting you want to save, I thought you were trying to save music being played by the user.

No, no… What I am talking about, lets say if they change it to disabled, it will save when they leave so they do not have to turn it on again.

--SERVER SCRIPT--
local DSService = game:GetService("DataStoreService")
local VolumeDS = DSService:GetDataStore("VolumeDS")
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")

Players.PlayerAdded:Connect(function(player)
	local key = "Volume_"..player.UserId
	local res = VolumeDS:GetAsync(key)
	if type(res) == "number" then
		RE:FireClient(player, res)
	end
end)

RE.OnServerEvent:Connect(function(player, volume)
	local key = "Volume_"..player.UserId
	local res = VolumeDS:SetAsync(key, volume)
end)
--LOCAL SCRIPT
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if game.SoundService.GameSound.Volume == 0.5 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
		RE:FireServer(game.SoundService.GameSound.Volume)
	elseif game.SoundService.GameSound.Volume == 0 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
		RE:FireServer(game.SoundService.GameSound.Volume)
	end
end)

RE.OnClientEvent:Connect(function(volume)
	if volume == 0.5 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
	elseif volume == 0 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
	end
end)

You may want to add a debounce to prevent things from being executed too frequently.
I’m not sure how things are organised on your end but you’ll need a RemoteEvent instance named “RemoteEvent” inside the “ReplicatedStorage” folder.

7 Likes

It doesn’t seem to save? In-game, and even in studio.

Mind uncopylocking/sharing the game file here? Feel free to message me instead. I don’t have the UI you’re working with so I’m unable to test.

Yea sure, just give me a minute.

Oh actually It does work, I put a LocalScript instead of a Script inside ServerScriptService! Thanks, I appreciate it!

No problem, with this method, in the future if you plan on having a slider which controls volume it’ll work for that too.

Am I doing my debounce wrong? Once I click, it doesn’t let me click again.

--LOCAL SCRIPT
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer
local db = false

script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		db = true
	if game.SoundService.GameSound.Volume == 0.5 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
		RE:FireServer(game.SoundService.GameSound.Volume)
	elseif game.SoundService.GameSound.Volume == 0 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
		RE:FireServer(game.SoundService.GameSound.Volume)
		end
	end
end)

RE.OnClientEvent:Connect(function(volume)
	if volume == 0.5 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
	elseif volume == 0 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
		
		wait(1)
		db = false
	end
end)
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer
local Debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if Debounce then
		return
	end
	Debounce = true
	if game.SoundService.GameSound.Volume == 0.5 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
		RE:FireServer(game.SoundService.GameSound.Volume)
	elseif game.SoundService.GameSound.Volume == 0 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
		RE:FireServer(game.SoundService.GameSound.Volume)
	end
	task.wait(1)
	Debounce = false
end)

RE.OnClientEvent:Connect(function(volume)
	if volume == 0.5 then
		game.SoundService.GameSound.Volume = 0.5
		script.Parent.BackgroundColor3 = Color3.new(0.0980392, 1, 0)
		script.Parent.Text = "On"
	elseif volume == 0 then
		game.SoundService.GameSound.Volume = 0
		script.Parent.BackgroundColor3 = Color3.new(1, 0.14902, 0.14902)
		script.Parent.Text = "Off"
	end
end)

Alright thank you! I was kinda confused, I understand now.