Locking things from a table?

Greetings, I’m trying to optimize my code and I was wondering how I could make a table dictate what’s locked and what isn’t

EXAMPLE code:

local OptionsLocked = {
	"Option1", false,
	"Option2", true,
	"Option3", true,
	"Option4", true,
	"Option5", false,
	
}

if Option1 == Locked then
	Options.Option1.Lock.Visible = true
	
end

How would I be able to do this?

local optionsLocked = {
  ["Option1"] = false,
  ["Option2"] = true,
  ["Option3"] = true,
  ["Option4"] = false,
  ["Option5"] = false,
}

-- example usage:
if optionsLocked["Option1"] then
  Options.Option1.Lock.Visible = true
end

In this example, optionsLocked is a table that maps option names to booleans, where a boolean value of true indicates that the option is locked, and false indicates that it is not locked.

In the provided example of usage, if Option1 is locked (as specified in the optionsLocked table), then the Visible property of the lock object (presumably somewhere in the Options object) will be set to true.

You can use this method to easily manage which options are locked or unlocked, and it can be easily extended to include additional options.

1 Like

You can create tables for boolean values like so. Using entire tables dynamically is done with a “for loop” iterating over pairs(OptionsLocked)

local OptionsLocked = {
	["Option1"] = false,
	["Option2"] = true,
	["Option3"] = true,
	["Option4"] = true,
	["Option5"] = false,

}

for key, value in pairs(OptionsLocked) do
	local object = Options:FindFirstChild(key)
	object.Lock.Visible = value
end
1 Like

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