Dictionary outputs a different value and how would I get a specific value

Hello I have attempted to get a specific value from a dictionary but failed to do so, and also it returns a different value then expected.

Module

{
    ["UserId"] = 2550824315,
    ["Tag"] = "Owner",
    ["Color"] = Color3.fromRGB(255, 255, 0)
},

{
    ["GroupId"] = 14109915,
    ["Rank"] = 255,
    ["Tag"] = "Owner",
    ["Color"] = Color3.fromRGB(255, 255, 0)
},

{
    ["GamepassId"] = 643697197,
    ["Tag"] = "Owner",
    ["Color"] = Color3.fromRGB(255, 255, 0)
}

Server

for num, data in pairs(Modules.NameTags) do
	for i, tag in pairs(data) do
		print(i, tag)
		if table.find(data, "Color") then
			print("Found color!")
		end
	end
end

and the output is:
10:34:33.396 Color 1, 1, 0 - Server - _MainServer:163
10:34:33.396 UserId 2550824315 - Server - _MainServer:163
10:34:33.396 Tag Owner - Server - _MainServer:163
10:34:33.397 Color 1, 1, 0 - Server - _MainServer:163
10:34:33.397 Tag Owner - Server - _MainServer:163
10:34:33.397 Rank 255 - Server - _MainServer:163
10:34:33.397 GroupId 14109915 - Server - _MainServer:163
10:34:33.397 Color 1, 1, 0 - Server - _MainServer:163
10:34:33.398 GamepassId 643697197 - Server - _MainServer:163
10:34:33.398 Tag Owner - Server - _MainServer:163

Sorry if this looks silly or dumb but it is my first time working with dictionaries, I’d be very thankful to anyone who’s able to solve this for me.

When you use table.find, it doesn’t check the dictionary for if theres a color index, its looking for the literal word “Color” in the table.

What you probably meant to do was something like this:

for num, data in pairs(Modules.NameTags) do
	for i, tag in pairs(data) do
		print(i, tag)
	end

    local Color = data.Color
    if Color then
        print("Found Color!", Color)
    end
end
1 Like

Thank you! Also do you know why the returned color value is: 1, 1, 0 instead of 255, 255 ,0?

Roblox just uses a 0-1 color scale internally instead of 0-255, you can pretty easily get the intended R,G,B value by just getting the individual color and just multiplying by 255

2 Likes

Thank you I’d give this a solution as well!

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