I have recently been trying to script a system where random events occur depending on a script that will look through a table and want to write efficient code.
As of right now I have made separate functions that all of these connect to, but for some reason none of them will execute whenever I choose an event.

Here is the code that is supposed to call the event, right now I have been using the BlurScreen function to test it.
Can anyone help me with this? I have a feeling it is an easy fix but can’t find a solution no matter what I do. Any help is appreciated!
PS I didn’t show the actual functions but the code doesn’t even get there so it isnt a problem with those, the error resides in trying to get the function to run
1 Like
Your declaring a variable that references the function. It doesn’t actually run it.
If you want the function to run from the module, you need to add the parenthesis at the end of the reference, like so;
local Event = module.SanityEvents.BlurScreen()
Thank you for the reply, I got this error:
Is there a way it will also run the function with all the values in the parenthesis? (In this screenshot):
You can’t put the parenthesis inside the table containing the functions. That makes the function run before even referencing it while setting the value to what is returned from the function.
I had to get a little creative with this solution, but here’s the fix;
local functions = {
testFunction = {test, {1, 2}}, -- a table in which the first index is the function (without parenthesis) and the second is the parameters
}
local functionData = functions.testFunction
functionData[1](table.unpack(functionData[2])) -- runs the function, which has index one, with the unpacked parameters
1 Like
Also, the math.random values are only set once, which means that the value will always be the same everytime the function is ran. There should be some easy ways to fix it, but that job up to either you or someone else. I’m only here to solve the main issue.
Thank you so much, I have been able to solve the issue