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")
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
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.
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.
----- 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)
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?