Help With saving In-Game Settings

How do you save in game settings this is all I know and is it possible to save in game settings by
Getting all the children-Values with 1 data store and saving them

here’s by script btw

	PL = DDS:GetDataStore("PlayerList"),
	SEV = DDS:GetDataStore("SoundEffectVolume"),
	MV = DDS:GetDataStore("MusicVolume"),
	AK = DDS:GetDataStore("Alignment_Keys"),
	DMSG = DDS:GetDataStore("DeathMessages"),
	UISC = DDS:GetDataStore("UiScale"),
	HPLR = DDS:GetDataStore("HidePlayers"),
	BTPL = DDS:GetDataStore("BLACKTOP_PLAYERLIST"),
	RT = DDS:GetDataStore("RespawnTime"),
	SNT = DDS:GetDataStore("ShowNameTag"),
	PS = DDS:GetDataStore("PartShadows"),
	ER = DDS:GetDataStore("EnableReset"),
	BC = DDS:GetDataStore("ButtonColor")
local PlayerList = Instance.new("BoolValue", SettingFolder)
	local SoundEffect = Instance.new("IntValue", SettingFolder)
	local MusicVolume = Instance.new("IntValue", SettingFolder)
	local Alignment_Keys = Instance.new("IntValue", SettingFolder)
	local DeathMessages = Instance.new("StringValue", SettingFolder) 
	local UiScale = Instance.new("IntValue",SettingFolder)
    local HidePlayers = Instance.new("BoolValue",SettingFolder)
	local RespawnTime = Instance.new("IntValue",SettingFolder)
	local ShowNameTag = Instance.new("BoolValue",SettingFolder)
	local PartShadows = Instance.new("BoolValue",SettingFolder)
	local EnableReset = Instance.new("BoolValue", SettingFolder)
	local ButtonColor = Instance.new("StringValue",SettingFolder)
	local BlacktopPlayerList = Instance.new("BoolValue",SettingFolder)
	PlayerList.Name = "PlayerListEnabled"
	SoundEffect.Name = "SoundEffectVolume"
	MusicVolume.Name = "MusicVolume"
	Alignment_Keys.Name = "Alignment_Keys"
	DeathMessages.Name = "DeathMessages"
	UiScale.Name = "UiScale"
	HidePlayers.Name = "HidePlayers"
	RespawnTime.Name = "RespawnTime"
	ShowNameTag.Name = "ShowNameTag"
	PartShadows.Name = "PartShadows"
	EnableReset.Name = "EnableReset"
	ButtonColor.Name = "Buttons"
	PlayerList.Value = true
	SoundEffect.Value = 1
	MusicVolume.Value = 1
	Alignment_Keys.Value = true
	DeathMessages.Value =  "Default"
	UiScale.Value = 1
	HidePlayers.Value = false
	RespawnTime.Value = 3
	ShowNameTag = true
	PartShadows = false
	EnableReset = false
	ButtonColor = "Normal"
	BlacktopPlayerList = false 

You shouldn’t have so many datastores for every setting, instead put all settings in a table and save that table as settings. You would do it like this:

--getting saved data
local success, plrsettings = pcall(function()
    return settingsStore:GetAsync(player.UserId)
end)

if success then
    for i,v in pairs(plrsettings) do
        if SettingFolder[i] then
            SettingFolder[i].Value = v
        end
    end
end

--saving data
local settingstable = {}
for i,v in pairs(SettingFolder:GetChildren()) do
    settingstable[v] = v.Value
end

local success, errorMessage = pcall(function()
    settingsStore:SetAsync(player.UserId, settingstable)
end)

if not success then
    print(errorMessage)
end
1 Like

uhhh do I setup a getdatastore?

do I have to setup the player leaving

Yes, same way you made all of those datastores for the settings, you just need to make one of them with :GetDataStore() and save the whole table of settings in that one datastore.

Depends on when you want to save the data, if you want it to save when player is leaving the game then yes.

yeah is that function when the player joins?

You would create datastore outside of the .PlayerAdded function, in the .PlayerAdded you would get players data, and in .PlayerRemoving you would save their data.


----- Services -----

local DDS = game:GetService("DataStoreService")
local Players = game:GetService("Players")

----- Global Datas -----

settingStore = DDS:GetDataStore("SettingsDataStore")

	

-----

Players.PlayerAdded:Connect(function(Plr)
	local SettingFolder = Instance.new("Folder", Plr)
	--i like it this name so you can change it --
	SettingFolder.Name = "SETTING_DATA"
	-- wow 5000 values--
	local PlayerList = Instance.new("BoolValue", SettingFolder)
	local SoundEffect = Instance.new("IntValue", SettingFolder)
	local MusicVolume = Instance.new("IntValue", SettingFolder)
	local Alignment_Keys = Instance.new("IntValue", SettingFolder)
	local DeathMessages = Instance.new("StringValue", SettingFolder) 
	local UiScale = Instance.new("IntValue",SettingFolder)
    local HidePlayers = Instance.new("BoolValue",SettingFolder)
	local RespawnTime = Instance.new("IntValue",SettingFolder)
	local ShowNameTag = Instance.new("BoolValue",SettingFolder)
	local PartShadows = Instance.new("BoolValue",SettingFolder)
	local EnableReset = Instance.new("BoolValue", SettingFolder)
	local ButtonColor = Instance.new("StringValue",SettingFolder)
	local BlacktopPlayerList = Instance.new("BoolValue",SettingFolder)
	PlayerList.Name = "PlayerListEnabled"
	SoundEffect.Name = "SoundEffectVolume"
	MusicVolume.Name = "MusicVolume"
	Alignment_Keys.Name = "Alignment_Keys"
	DeathMessages.Name = "DeathMessages"
	UiScale.Name = "UiScale"
	HidePlayers.Name = "HidePlayers"
	RespawnTime.Name = "RespawnTime"
	ShowNameTag.Name = "ShowNameTag"
	PartShadows.Name = "PartShadows"
	EnableReset.Name = "EnableReset"
	ButtonColor.Name = "Buttons"
	PlayerList.Value = true
	SoundEffect.Value = 1
	MusicVolume.Value = 1
	Alignment_Keys.Value = true
	DeathMessages.Value =  "Default"
	UiScale.Value = 1
	HidePlayers.Value = false
	RespawnTime.Value = 3
	ShowNameTag = true
	PartShadows = false
	EnableReset = false
	ButtonColor = "Normal"
	BlacktopPlayerList = false 
	--- Saved Progress
	local success, plrsettings = pcall(function()
		return settingStore:GetAsync(Plr.UserId)
	end)

	if success then
		for i,v in pairs(plrsettings) do
			if SettingFolder[i] then
				SettingFolder[i].Value = v
			end
		end
	end
Players.PlayerRemoving:Connect(function(leftPlayer)
	local settingstable = {}
	for i,v in pairs(leftPlayer:WaitForChild("SETTING_DATA"):GetChildren()) do
		settingstable[v] = v.Value
	end

	local success, errorMessage = pcall(function()
		settingStore:SetAsync(leftPlayer.UserId, settingstable)
	end)

	if not success then
		print(errorMessage)
	end
	end)
	end)

Actually here you need to do settingstable[v.Name] = v.Value i forgot to add .Name.

Here you should change it to if success and plrsettings then so if theres no saved settings it doesnt try to apply them. Also move .PlayerRemoving function out of the .PlayerAdded.

not working


----- Services -----

local DDS = game:GetService("DataStoreService")
local Players = game:GetService("Players")

----- Global Datas -----

settingStore = DDS:GetDataStore("SettingsDataStore")

	

-----

Players.PlayerAdded:Connect(function(Plr)
	local SettingFolder = Instance.new("Folder", Plr)
	--i like it this name so you can change it --
	SettingFolder.Name = "SETTING_DATA"
	-- wow 5000 values--
	local PlayerList = Instance.new("BoolValue", SettingFolder)
	local SoundEffect = Instance.new("IntValue", SettingFolder)
	local MusicVolume = Instance.new("IntValue", SettingFolder)
	local Alignment_Keys = Instance.new("IntValue", SettingFolder)
	local DeathMessages = Instance.new("StringValue", SettingFolder) 
	local UiScale = Instance.new("IntValue",SettingFolder)
    local HidePlayers = Instance.new("BoolValue",SettingFolder)
	local RespawnTime = Instance.new("IntValue",SettingFolder)
	local ShowNameTag = Instance.new("BoolValue",SettingFolder)
	local PartShadows = Instance.new("BoolValue",SettingFolder)
	local EnableReset = Instance.new("BoolValue", SettingFolder)
	local ButtonColor = Instance.new("StringValue",SettingFolder)
	local BlacktopPlayerList = Instance.new("BoolValue",SettingFolder)
	PlayerList.Name = "PlayerListEnabled"
	SoundEffect.Name = "SoundEffectVolume"
	MusicVolume.Name = "MusicVolume"
	Alignment_Keys.Name = "Alignment_Keys"
	DeathMessages.Name = "DeathMessages"
	UiScale.Name = "UiScale"
	HidePlayers.Name = "HidePlayers"
	RespawnTime.Name = "RespawnTime"
	ShowNameTag.Name = "ShowNameTag"
	PartShadows.Name = "PartShadows"
	EnableReset.Name = "EnableReset"
	ButtonColor.Name = "Buttons"
	PlayerList.Value = true
	SoundEffect.Value = 1
	MusicVolume.Value = 1
	Alignment_Keys.Value = true
	DeathMessages.Value =  "Default"
	UiScale.Value = 1
	HidePlayers.Value = false
	RespawnTime.Value = 3
	ShowNameTag = true
	PartShadows = false
	EnableReset = false
	ButtonColor = "Normal"
	BlacktopPlayerList = false 
	--- Saved Progress
	local success, plrsettings = pcall(function()
		return settingStore:GetAsync(Plr.UserId)
	end)

	if success and plrsettings then
		for i,v in pairs(plrsettings) do
			if SettingFolder[i] then
				SettingFolder[i].Value = v
			
			end
		end
	end



	Players.PlayerRemoving:Connect(function(leftPlayer)
	local settingstable = {}
	for i,v in pairs(leftPlayer:WaitForChild("SETTING_DATA"):GetChildren()) do
		settingstable[v.Name] = v.Value
	end

	local success, errorMessage = pcall(function()
		settingStore:SetAsync(leftPlayer.UserId, settingstable)
	end)

	if not success then
		print(errorMessage)
	end

	
	end)
end)

Did you enable API Services? Go to Game Settings > Security and enable Enable Studio Access to API Services.

Also, here you are just replacing the variable with the value instead of changing its value, since you forgot the .Value.

fixed that and still not working

its on anyway so I guess something is wrong here

Tested your script and the only thing you could change is:

Instead of if SettingFolder[i] then put if SettingFolder:FindFirstChild(i) then. Other than that everything else should work fine.

--- Made by Yqta (Alt)

----- Services -----

local DDS = game:GetService("DataStoreService")
local Players = game:GetService("Players")

----- Global Datas -----

settingStore = DDS:GetDataStore("SettingsDataStore")

-----

Players.PlayerAdded:Connect(function(Plr)
	local SettingFolder = Instance.new("Folder", Plr)
	local Folder = Instance.new("Folder", Plr)
	Folder.Name = "SettingsData"
	
	
	
	SettingFolder.Name = "SETTING_DATA"
	-- wow 5000 values--
	local PlayerList = Instance.new("BoolValue", SettingFolder)
	local SoundEffect = Instance.new("IntValue", SettingFolder)
	local MusicVolume = Instance.new("IntValue", SettingFolder)
	local Alignment_Keys = Instance.new("IntValue", SettingFolder)
	local DeathMessages = Instance.new("StringValue", SettingFolder) 
	local UiScale = Instance.new("IntValue",SettingFolder)
	local HidePlayers = Instance.new("BoolValue",SettingFolder)
	local RespawnTime = Instance.new("IntValue",SettingFolder)
	local ShowNameTag = Instance.new("BoolValue",SettingFolder)
	local PartShadows = Instance.new("BoolValue",SettingFolder)
	local EnableReset = Instance.new("BoolValue", SettingFolder)
	local ButtonColor = Instance.new("StringValue",SettingFolder)
	local BlacktopPlayerList = Instance.new("BoolValue",SettingFolder)
	PlayerList.Name = "PlayerListEnabled"
	SoundEffect.Name = "SoundEffectVolume"
	MusicVolume.Name = "MusicVolume"
	Alignment_Keys.Name = "Alignment_Keys"
	DeathMessages.Name = "DeathMessages"
	UiScale.Name = "UiScale"
	HidePlayers.Name = "HidePlayers"
	RespawnTime.Name = "RespawnTime"
	ShowNameTag.Name = "ShowNameTag"
	PartShadows.Name = "PartShadows"
	EnableReset.Name = "EnableReset"
	ButtonColor.Name = "Buttons"
	PlayerList.Value = true
	SoundEffect.Value = 1
	MusicVolume.Value = 1
	Alignment_Keys.Value = true
	DeathMessages.Value =  "Default"
	UiScale.Value = 1
	HidePlayers.Value = false
	RespawnTime.Value = 3
	ShowNameTag.Value = true
	PartShadows.Value = false
	EnableReset.Value = false
	ButtonColor.Value = "Normal"
	BlacktopPlayerList.Value = false 
	--- Saved Progress
	local success, plrsettings = pcall(function()
		return settingStore:GetAsync(Plr.UserId)
	end)

	if success and plrsettings then
		for i,v in pairs(plrsettings) do
			if SettingFolder:FindFirstChild(i) then
				SettingFolder[i].Value = v
				print(v)
			end
		end
	end



	Players.PlayerRemoving:Connect(function(leftPlayer)
		local settingstable = {}
		for i,v in pairs(leftPlayer:WaitForChild("SETTING_DATA"):GetChildren()) do
			settingstable[v.Name] = v.Value
		end

		local success, errorMessage = pcall(function()
			settingStore:SetAsync(leftPlayer.UserId, settingstable)
		end)

		if not success then
			print(errorMessage)
		end


	end)
end)

not working with

not working… with something has to be wrong

it is not working so I guess you need to found out how to save a folder with the same values

As I said I tested your script and it should work so I really dont know whats wrong. Is it a LocalScript instead of a Script? Where is it located and is there any errors in output?

how do I test it tho… I don’t want it to mess up my settings