Help with running functions that are inside a dictionary

  1. What do you want to achieve? Keep it simple and clear!
    I want to run functions that are inside a dictionary with use of arguments instead of straightly using the variables.

  2. What is the issue? Include screenshots / videos if possible!
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried doing this, but to no avail.
    Can you run a function in a table?

local Race = "Raceless"

local Races = {"Dragonborn", "Jhaltar"}

local function ApplyRace(Race)
	if Race == "Raceless" then
		local chosenRace = math.randomseed(os.time())
		chosenRace = Races[math.random(1, #Races)]
		Race = chosenRace
	end
end

local function DefineTraits(Types)
	local randomType = math.randomseed(os.time())
	randomType = Types[math.random(1, #Types)]
	print(randomType)
end

local RacesInfo = {
	["Dragonborn"] = {function()
		local Types = {
			[1] = {"Blue"},
			[2] = {"Red"},
			[3] = {"White"},
			[4] = {"Silver"},
			[5] = {"Gold"},
			[6] = {"Bronze"}
		}

		DefineTraits(Types)
	end
	},

	["Jhaltar"] = {function()
		local Types = {
			[1] = {"Pastel Brown"},
			[2] = {"Pale White"}
		}

		DefineTraits(Types)
	end
	}
}

local function Main(Race)
	RacesInfo[Race]()
end

ApplyRace(Race)
wait(1)
Main(Race)

This is my first post, thank you in advance for the answers that you’ll be giving.
If my question already has an obvious answer, then I apologize for my ignorance.

1 Like

You don’t need to wrap the function in a table with {function() .... }. When you call RacesInfo[Race]() it is calling the table {function() ... }, not the function. Just remove the squiggly braces so the function isn’t in its own table.

1 Like

Holy, thank you so much. Brain farts are a common occurrence!

1 Like