So, as part of a dialogue tree system, I’ve been inserting functions into dictionaries. The dialog tree is one giant nested dictionary in a moduleScript.
Currently, I have a localScript that requires the dialogue module and eventually gets to a list that contains the function.
{"exitDialogue", "serverFunction", function(plr)
plr.Character:FindFirstChild("tickedOffJup").Value = true
end}
In my localScript, the function is called using something like:
endList[3](plr)
Where the endList refers to the list above. It works there, but only runs on the client. I wanted to make it run on the server, so I decided to fire a RemoteEvent to a serverScript. I pass through the player and endList[3]
.
When the serverScript receives it though:
choiceFuncEvent.OnServerEvent:Connect(function(plr, functionToRun) -- if there's a function to be ran during dialog and it's labeled a "serverFunction", it hands the job here.
print(functionToRun)
functionToRun(plr)
end)
The argument functionToRun
returns nil. From what I can see, it should be the function’s hexadecimal memory address, and I don’t get why it just seems to…break upon being passed through an event. At least, I think it’s the memory address. Maybe it’s referring to the function inside the moduleScript? When I printendList[3]
, I get:
function: 0x2b289b9ae7d49269
I’m also pretty sure this isn’t because I forgot to require the moduleScript, as the argument I’m passing here already comes from the localScript, which has required the dialogue module. Besides, shouldn’t it just be passing the function? I’m stumped here.
TL;DR: I’m trying to pass a function through a RemoteEvent, but it comes out as nil when received. By passing a function, it might actually be its memory address.