I want to create a settings menu that is well, any other settings menu, but it also interacts like I can set if I want guns to always reload when their magazine is at zero, However I do not know how to execute this, I wanna know the most performant way, like is it gonna be a bunch of attributes/values inside a folder stored inside the player?, A modulescript? or just any other regular local/server script.
It is basically a bunch of boolean and other values that you store among others player datas. Then, you can implement some if conditions
inside your differents scripts to change their behavior depending of theses values.
Hello, recently I created a Options menu for my game, here is how I did it.
Main Module
--[[
functions:
local options = OptionsModule.CreateOptions(table, parent)
table -> the table with all the options you want to add
parent -> not necesary but where the options go after created
options:GetOptionValue(optionName) -- returns the value
options:SetOptionValue(optionName) -- set the value
optionName -> the name of the option, example "Volume"
]]
local OptionsModule = {}
OptionsModule.__index = OptionsModule
function OptionsModule.CreateOptions(optionsList, parent : Folder?)
local self = setmetatable({}, OptionsModule)
self.OptionsCreated = {}
self.OptionsByName = {}
local folder = Instance.new("Folder")
folder.Name = "OptionsFolder"
folder.Parent = parent or script
for _, option in ipairs(optionsList) do
local success, newOption = pcall(function()
local instance = Instance.new(option.Type)
instance.Name = option.Name
instance.Value = option.StartedValue
instance.Parent = folder
return instance
end)
if success and newOption then
table.insert(self.OptionsCreated, newOption)
self.OptionsByName[newOption.Name] = newOption
else
warn("Error creating option:", option.Name)
end
end
self.Folder = folder
return self
end
function OptionsModule:GetOptionValue(optionName)
local option = self.OptionsByName[optionName]
if option then
return option.Value
else
warn("Option not found:", optionName)
end
end
function OptionsModule:SetOptionValue(optionName, newValue)
local option = self.OptionsByName[optionName]
if option then
option.Value = newValue
else
warn("Option not found:", optionName)
end
end
return OptionsModule
Use Example
local OptionsModule = require(script.Options) -- path to the module
local optionsList = { -- put any option you want to create
{ Type = "BoolValue", Name = "MusicEnabled", StartedValue = true },
{ Type = "IntValue", Name = "Volume", StartedValue = 5 },
}
local options = OptionsModule.CreateOptions(optionsList, game.ReplicatedStorage) -- creates the options
print(options:GetOptionValue("MusicEnabled")) -- true
options:SetOptionValue("Volume", 10)
Use the module on the client side obviously, create everything you want and then check if the player is activating the option, you can use sliders too, I used it with this module, really cool use.
1 Like
i would recommend using a switch module alongside any working suggestions in this thread to avoid having a ton of unnecessary else-ifs, i would also say to use a simple modulescript and use values and attributes