Multiple Variables in a Table Set to The Same Value

Hi, this problem is really simple but I don’t know how to solve it :sob:

	local AssetTypes = {
		["Sound"] = "SoundId";
		["ImageLabel", "ImageButton"] = "Image";
		["Decal"] = "Texture"
	}

I’m trying to have two strings (“ImageLabel” and “ImageButton”) set to one string (“Image”) in a table but I don’t know how to do it. The way I’ve done it is incorrect and doesn’t work as I intended.

If you’re wondering, I’m using this for an asset loading system to preload all of the assets ingame (with ContentProvider) before the player spawns in.

Help is appreciated !

Currently testing with a short line of code in the console:

local AssetTypes = {["ImageLabel" and "ImageButton"] = "Image"} local decal = Instance.new("ImageLabel"); print(AssetTypes[decal.ClassName]); decal:Destroy()

The code returns ‘nil’.

Neither of the trials will work, it Roblox, only single-indexes are possible so you can’t do this, your can try to either remove the clones or just have it there or, invert the tables so that the “Image” is the key and the value is a table containing “ImageLabel” and “ImageButton”

local AssetTypes = {
		["Sound"] = "SoundId",
		[ "ImageButton"] = "Image",
                ["ImageLabel"] = "Image",
		["Decal"] = "Texture"
	}

I don’t know of any shorter way do write it.

To help with your problem, the key evaluates to “ImageButton” so it’ll be:

local AssetTypes = {["ImageButton"] = "Image"}

That’s why it returned nil when u tried it with ImageLabel. Reason is, your using and which checks if the thing before it is true (or non-nil) and if so, will evaluate to the value after it, if not, it will look for an or if there is, it will evaluate to it, if not, it will evaluate to nil.

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