My setting bar i made when you leave the game it resets when you rejoin how would I fix that?
How would I save it, if it has to do with the setting bar?
You can save BoolValues
Values to detect whenever a player leaves/joins the game, so that it’s able to save the data
This is probably the most simplest option, since the Settings
bar can have 2 options for each, if there are more than 2 then you can use Number
or String
values in this Instance
Example:
local DataStore = game:GetService("DataStoreService")
local GetData = DataStore:GetDataStore("SettingsBar")
game.Players.PlayerAdded:Connect(function(Player)
local Settings = Instance.new("Folder")
Settings.Name = "Settings"
Settings.Parent = Player
local Detail = Instance.new("BoolValue")
Detail.Name = "HighDetail"
Detail.Parent = Settings
local Colorblind = Instance.new("BoolValue")
Colorblind.Name = "Colorblind"
Colorblind.Parent = Settings
local DataToLoad
local success, whoops = pcall(function()
DataToLoad = GetData:GetAsync(Player.UserId)
end)
if success and DataToLoad then
Detail.Value = DataToLoad.Detail
Colorblind.Value = DataToLoad.Colorblind
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local Data = {
Detail = Player.Settings.HighDetail.Value;
Colorblind = Player.Settings.Colorblind.Value; --You can add more if you want
}
local success, whoops = pcall(function()
GetData:SetAsync(Player.UserId, Data)
end)
if success then
print("Saved data successfully")
else
warn(whoops)
end
end)
save setting bools to datastores, then get the stored value of the player.
Will it still work if the setting stuff is in the GUI
I mean yes, but it depends on how you’ve structured your code. If it’s poorly structured then it could be difficult to have your settings frame reflect the player’s adjusted settings.
Ideally there should be a clear place where you store settings be it a folder of ValueObjects, an instance with attributes or a ModuleScript (best option imho). This is what the client will send to the server to save in a player’s data table for future sessions. This also makes it easier to reference when setting up the game or needing to use a setting during an event in the game.
When a player joins the game, the server can fetch the player’s data and send the saved settings to the client. It can then update its holding location with the pulled settings (the aforementioned folder, attributes or ModuleScript options) and then the Gui with the current settings as well.
So for example if someone puts setting on high graphics when they leave and rejoin it won’t reset?
You need to look at this from a different perspective. It will always “reset” when a player rejoins to the default values given. What you’re trying to accomplish here is saving and loading player settings to the current session to overwrite the default values.
Ahh, okay! I see what your coming from. I think i can mange that thank you sir/miss.