You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Be able to run functions from a table
-
What is the issue? It’s not being detected?
-
What solutions have you tried so far? Having someone else read over the code, I was looking at the forum for multiple hours trying to find something useful but nothing helped.
Bellow is the table with the function inside which is just supposed to print “hello” when it is used, this table is inside a module:
local NPC = {}
function NPC.info(plr)
return {
info = {
Name = "Med"
},
dialogue = 1,
dialogues = {
[1] = {
{
Dialogue = "You are dead.",
Answers = {
[1] = {"Accept fate.", "End", Func = function() print("hello") end} -- the function inside the table
}
},
},
}
}
end
return NPC
bellow is the line on a server script which then sends the info to the client:
context = require(Dialogues[v.Name]).info(player) --gets the info depending on which npc is clicked
Event:FireClient(player, context) --fires it to a local script
here are some lines from the client where I’m supposed to be finding/using the function:
for i = 1, #currentdialogue.Answers do
local NewButton = Choices.Answer:Clone()
NewButton.Text = currentdialogue.Answers[i][1]
NewButton.Parent = Choices.Choices
NewButton.Visible = true
NewButton.MouseButton1Click:connect(function()
answer(currentdialogue.Answers[i][1], currentdialogue.Answers[i][2], currentdialogue.Answers[i]["Func"]) -- the function
end)
end
GUI.Visible = true
end
function answer(Dialogue, newPath, Func)
print(Dialogue.." "..newPath)
if newPath ~= "End" then
path = newPath
for i, v in pairs(Choices.Choices:GetChildren()) do
if v:IsA("TextButton") then
v:Destroy()
end
end
update(Context)
else
path = 1
GUI.Visible = false
end
if Func ~= nil then -- check if there is a function named Func
print("there is a function") -- this prints if it's not nil
Func() -- use the function
end
end
I do not understand why it comes out as nil as it’s clearly there. Everything else can be found in the table except the function, help?