Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get the name of a value in a table?

So, I currently have a script which is something like this:

local commands  = {}

commands.kill = function()
	--function goes here.
end

commands.cmds = function()
	for i,v in pairs(commands) do
		local clone = --Removed this part
		clone.Name = v -- So if v was the "kill" function, how would I get the name "kill" as a string?
	
end

Where it says clone.Name = v I would like to get the name (for example "kill") of the value in the table. How would I do this?

1 answer

✓ Accepted answer

In an array, i = values location in table In a dictionary, i = Values identefier in table

For example

local array = {"A","B","C")
local dictionary = {
	["Alphabet1"] = "A";
	["Alphabet2"] = "B";
	["Alphabet3"] = "C"
}
wait(1)
print("ARRAY:")
for i,v in pairs(array) do
	print(v.." is the "..i.." value in this array")
	wait(.5)
end
wait(1)
print("DICTIONARY:")
for identefier, value in pairs(dictionary) do
	print(identefier.." will return "..value.." in this dictionary")
	wait(.5)
end

Once you type this code, just look at the output prints for a better understanding of the topic! I hope I was able to help. ~mc3334

2 comments

0

Thanks!

0

Np

This discussion is preserved as it was. New answers, comments, and votes are closed.