How would I correctly call a function from a table?

I am storing round values in a table for my game, these values include the function for round the game would run. Yet the function doesn’t run and there are no errors. This is what I have:

local module = {}
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local GameModes = {
	--["NAME"] = {function,roundName,roundTime,winXP,winCred}
	{swordFFA,"Sword Free For All",60,45,150}
}
function spawnPlayersForRound()
	for _,Player in pairs(Players:GetPlayers()) do
		Player.Team = Teams:WaitForChild("Round")
		Player:LoadCharacter()
	end
end

-- Modes
function swordFFA()
	print("abc") -- This does not print
	spawnPlayersForRound()
	for _,Player in pairs(Players:GetPlayers()) do
		ServerStorage.Tools.Sword:Clone().Parent = Player.Backpack
		local newField = Instance.new("ForceField",Player.Character)
	end
	ReplicatedStorage.RoundEvent:FireAllClients("Start",{5})
	wait(5)
	for _,Player in pairs(Players:GetPlayers()) do
		if Player.Character:FindFirstChild("ForceField") then
			Player.Character.ForceField:Destroy()
		end
	end
	return "end"
end

-- Main Start
function module.startGame()
	local Mode = GameModes[math.random(1,#GameModes)]
	ReplicatedStorage.RoundValues.RoundTime.Value = Mode[3] -- These values are set correctly.
	ReplicatedStorage.RoundValues.RoundName.Value = Mode[2] -- These values are set correctly.
	local Run = Mode[1]
	print("ok") -- This does print
	if Run == "end" then
		print("Round Over!") -- This does not print, even after 5 seconds
		return Run
	end
end
return module

How would I do this? Or what am I doing incorrectly? Thanks.

Change this to local Run = Mode[1]()

1 Like

Changing that returns this error; Screenshot by Lightshot

Thats because swordFFA isn’t defined yet in your script. Move local GameModes to be right above module.startGame()

Ah. I see, thank you for your help. Problem solved.

1 Like