Storing Objects

  1. I wanna store the player’s settings for their next visit

  2. I was just wondering if I could store that data using object values. Can I store, for example a config, in an object value? or do i have to store every single setting

Thanks in advance!

1 Like

You can store player settings in an ObjectValue, Instead of saving each setting as a separate property, you can create a single ObjectValue that contains all the configuration data in a structured format like a table, you can create an ObjectValue in the player’s instance, then store a table in the ObjectValue to hold the settings

-- Saving settings
local player = game.Players.LocalPlayer
local settings = {
    volume = 0.5,
    graphicsQuality = 3,
    controls = "WASD"
}

-- Convert settings table to a string (for storage)
local settingsString = game.HttpService:JSONEncode(settings)
player:SetAttribute("Settings", settingsString)

-- Loading settings
local loadedSettingsString = player:GetAttribute("Settings")
local loadedSettings = game.HttpService:JSONDecode(loadedSettingsString)

print(loadedSettings.volume) -- Example of accessing a specific setting

It should hopefully provide easier management, and will make it easier to add or change settings without modifying too many lines

1 Like

Oh okay, but can I store a configuration? its a roblox object.

im asking because I didnt really understand your example;
can’t an object value only store objects? then how is it going to store a table???

1 Like

Oh yeah sorry, yeah an ObjectValue can only store objects not tables or strings, you can use a folder or model to contain all the individual settings as separate ObjectValues

local player = game.Players.LocalPlayer
local settingsFolder = Instance.new("Folder")
settingsFolder.Name = "PlayerSettings"
settingsFolder.Parent = player

-- Create ObjectValues for each setting
local volumeSetting = Instance.new("ObjectValue")
volumeSetting.Name = "Volume"
volumeSetting.Value = Instance.new("IntValue", settingsFolder)
volumeSetting.Value.Value = 50 -- Example value

local graphicsSetting = Instance.new("ObjectValue")
graphicsSetting.Name = "GraphicsQuality"
graphicsSetting.Value = Instance.new("IntValue", settingsFolder)
graphicsSetting.Value.Value = 3 -- Example value

-- Add more settings as needed

And to retrieve the settings later, you can just look for the settings in the PlayerSettings folder

local volume = player.PlayerSettings.Volume.Value.Value
local graphicsQuality = player.PlayerSettings.GraphicsQuality.Value.Value

print("Volume: " .. volume)
print("Graphics Quality: " .. graphicsQuality)

This should work well with the settings and all, while still following to the Roblox limitations on ObjectValue

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.