Freeze Index Function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

a index freezer

  1. What is the issue? Include screenshots / videos if possible!

i no know how to make it

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

yes

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function FI(t: table,i: any): table -- FreezeIndex
-- CODE
end

local t = {a = 3,b = 3}

FI(t,"a")

t.b = 2 -- set to 2
t.a = 2 -- returns error

if you no understand you can test Part.ClassName = any and outs a error but Part.Position = any no outs

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

table.freeze(nice_table)

there is no documentation for table.freeze for some reason but it exists and works

Im confused about your topic, but i think table.freeze doesn’t do much if it was added. because you could’ve just disabled the table.insert/ table.remove/ others.

is to freeze index

a instance have property/indexs

but ones can’t change is only read
but others yes can change on the self instancec

how

Instance.ClassName = any – error
Instance.Position = Vector3 – no error

1 Like

ClassName isn’t assignable, Position is.

You could implement this logic inside of the __index metamethod of the table possibly. Something like this:

local exampleTable = {"a", "b"}

local function freezeIndex(t, index)
	setmetatable(t, {
		__index = function(t, k)
			-- CODE
		end,
	})
end

freezeIndex(exampleTable, "a")

print(exampleTable[1]) -- not valid

print(exampleTable[2]) -- valid

I don’t know the exact implementation but I would approach this with metatables considering the syntax you’re using in your original post.

When you say it like that it kinda confuses me.

imagine a function that make unchangable index but no others

local table = {}

table.A = 3
table.B = 3

FI(table,"A")

table.A = 2 -- can't change for freezing index and returns error

table.B = 2 -- this index is not freezed then not happens nothing and change to 2

maybe check if that index’s last value was nil then if it is set it an __index to always be its last value therefore unchangeable?