Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do I get an error from using a function from an Module but not from a LocalScript? [ANSWERED]

So I have to have a function for an action for ContextActionService, I looked in the wiki and they put the function without the two parenthesis. If you do put the two parenthesis then you actually call the function and return something else.

Here's how in the LocalScript I make an action with ContextActionService. I actually use a ModuleScript since I can create actions and bind them on the go easily.

ContextModuleScript:CreateAction(
	HumanoidModuleScript:HumanoidSprint(), -- the function itself,
	Enum.KeyCode.LeftShift, -- input 
	"Sprint" -- string action name
)

However that returns me an error, that function up there is nil, here's why. When you pass a function and include it's brackets. It actually calls the function no matter what and automatically returns the nil value because my function doesn't return a value at all.

When I remove those two brackets, I end up with a syntax error. I do this with functions that are not in ModuleScripts and it does not error at all.

How come functions in ModuleScripts (functions that are in tables) do not behave the same way functions that are local/global.

Instead of a colon that is indexing the function, I tried it with a dot. I went ahead to test it and it surprisingly worked. I don't know why that worked but is it possible to index functions with a colon? Do I have to index it some other way?

1 answer

I didnt write the answer long ago but here it is, yes I have to index it with a dot and not a colon.

This discussion is preserved as it was. New answers, comments, and votes are closed.