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

Can a dictionary key value (if a table) hold multiple values?

can ignore this stuff if you get question:

/~~~~~~~~~~~~~~~~~ Functions = {

CreateConfiguration = (function(Configurations, Table)
	--gets the table of the first parameter
	for i, v in pairs(Configurations:GetChildren()) do
		
		--finds if the values classname is a value
		if string.find(v.ClassName, "Value") then
			--if it make its name a clone of its value
			
			print(v.Name)  
			Table[v.Name] = v:Clone()
			
			--if it isnt and it is either a folder or configuration class 
			print(Table)
		elseif v:IsA("Folder") or v:IsA("Configuration") then
			--then make the values name become
			Table[v.Name] = Functions.CreateConfiguration(v, Table)
			print(Table[v.Name])
		end
		print(Table)
	end~~~~~~~~~~~~~~~~~

The line 16 for some reason ends up making 2 values when I print the table it makes. I don’t know why this happened.

print log: ~~~~~~~~~~~~~~~~~ ["Ammo"] = "*** cycle table reference detected ***", ["Automatic"] = Automatic, ["Bullets"] = Bullets, ["Burst"] = "*** cycle table reference detected ***", ["ClipSize"] = ClipSize, ["Damage"] = Damage, ["FireRate"] = FireRate, ["Magazines"] = Magazines, ["Offset"] = Offset, ["Range"] = Range, ["ReloadTime"] = ReloadTime, ["ToolName"] = ToolName

Burst is the folder  then offset and bullets are its children.

2 answers

You are running the function. Now it gets to line 16, waits there and runs the same function again on line 16. Now that you are running it again, it is printing. Because it now is finished, the function you first ran can now resume on line 17 and also Prints.

voilla, you have multiple prints because you are running multiple functions.

Edit: And no, a dictionary key can not hold multiple values

No, you can’t. But you can turn multiple values into a table so it will be one value.

local SomeTable = {
   foo = "bar", "boo" --wrong
   
   bar = {"foo", "boo"} --correct
}

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