How to compare values of two different tables?

Title is actually quite misleading as I already know how to do that, but I have a problem with the values not setting afterwards.

--keys: Several stringvals in a folder
--hotkey: Textlabel (textbox as descendant)
for _, v in pairs (keys:GetChildren()) do
		for i = 1, #hotkey do
			if v.Name == hotkey[i].Name then
				print('true') -- prints it once after it iterates through everything else
                v.Value = hotkey[i].TextBox.Text 

No errors. I guess setting v’s value affected the rest of the values as well. Any insight?

What exactly is “hotkey”? If it is a TextLabel object, then you can not use “# hotkey” on it.

Sorry I wasn’t quite clear. Hotkey is a frame that holds textlabels. Whenever I tweaked it a bit, the text does show up, but it seems like its setting to the first value that I put. I guess im setting them all to one value.

What are you trying to get by using a length operator on a Frame?

Trying to make a temporary save system for a hotkey system that I have.
Keys: Folder with stringvalues (Name of skills that will be binded)
HotKey: Frame that holds textlabels (with textbox as descendant) and share the same amount and names with ‘Keys.’

Well, as the title says, im comparing both values from their respective tables, which works up to that point btw.

When you’re comparing values from tables, what are you trying to achieve?

The # operator is only used to determine the length of strings, or tables. Using on a Frame GUI object will not work. Are you trying to get the number of Children inside the Frame?

The textboxes are running a changed event, so I fire that snippet of a whole to change the key’s value to the key that was inputted. Then I have the character on spawn input the key’s value to their hotkeys (textlabel>textbox)

You aren’t wrong, but just above that code (didnt show it as I explained it already), I iterated the hotkey, and the # operator is ran in a for loop so it runs the amount of children it has.

code above that went sumn like:

local hotkey = ui.Hotkeys:GetChildren()

–proceed with rest of code

1 Like

I still don’t entirely get the purpose of your code. All your given us is a snippet and we’re left to guess what you’re using it for, what might be wrong and what alternatives there could be.

That snippet is literally the main idea of the code, but if it’ll help then heres the full code:

local Change = function(plyr, input)
	local char = plyr.Character
	local values = plyr:FindFirstChild("Values")
	local keys = values:FindFirstChild("Keys")
	local ui = plyr.PlayerGui:FindFirstChild("UI")
	local hotkey = ui:FindFirstChild("Hotkey"):GetChildren()
	for k, v in pairs (keys:GetChildren()) do
		for i = 1, #hotkey do
			if v.Name == hotkey[i].Name then
				local tb = hotkey[i]:FindFirstChild("TextBox")
				if tb then
					v.Value = input
				--v.Value = tostring(hotkey[i].Name)


In simpler words:

Whenever a player changed their keybind, I want it to register and save that input in keys.

Instead of having to iterate through all the values in a table, you could simply set up a dictionary and directly index it.

Read a bit bout it just now. Am I able to set a whole path in a dictionary?

local tab = {
skill = keys.skill

Is that what you meant? if not, please enlighten me

Assuming keys is a dictionary, you can index it through a.b or a["b"], although I prefer the latter.

1 Like

got an idea, ty. dsafsfsafsfdsf

1 Like