What's wrong with this dictionary key?

I can’t figure this out. If anyone has any clue of why trying to access it normally does not work i’d appreciate it.

This line right here errors as it seems “Height” is nil in my AvatarData dictionary.

playerData.Avatar.Height.Value = slotData.AvatarData["Height"];

However, printing the dictionary returns this:
capture

The nil below is what is printed if I try printing slotData.AvatarData.Height.
To make sure I was not mistaken or was somehow using the wrong dictionary, I went on to print every key and every value of it, and funnily enough height does exist.

for key, value in pairs(slotData.AvatarData) do
	print(key, value);
	if key == "Height" then
		print("I found the height, roblox is trolling.");
	end;
end;

capture2

Am I tripping? Did I make some basic mistake that I cannot see? Or is Roblox actually trolling me? Thank you!

2 Likes

Does it index other keys like Width?

Yeah, only the Height returns nil. It’s confusing me quite a lot. I had to use this workaround to make it work.

local Height = 1;
for key, value in pairs(slotData.AvatarData) do
	if key == "Height" then
		Height = value;
	end;
end;

playerData.Avatar.Height.Value = Height;

Not ideal but getting the value from the dictionary won’t work.

Topic still open in case anyone has an explanation for what’s going on here.

No idea what’s happening, but try rawget(table, 'Height').

Your data is being loaded async possibly which makes the table empty initially. Try to time your loading with it as soon as it is loaded.

2 Likes

But then why in the for loop (that comes first) I can find the height but by directly accessing it from the dictionary (which happens after) I can’t?

The timing of the operations are very minimal and hard to notice. Direct accesses have a simple complexity of O(1) as opposed to O(n). Because of this subtle difference, it makes an impact regardless.

1 Like

So I imagine adding a simple task.wait() could fix the issue?

I suppose it would? It’s not fully reliable but a possibility. The better fix is to find an event or writing it with time in mind to track of.

I know nothing about this, but try this:

Instead of using AvatarData["Height"] try using AvatarData.Height

Ok,the only thing i know about is that there are two functions,table.array and table.insert.But