i want to make a function be able to be done from any scrit, for example a function to make a print happen
How do i add a function to a module script to run it from any other script
1 Like
This is how im using it on my games
function on your module script:
function yourfunction(yourparameter)
--logic
return yourfunction
on your script:
local YourFunction = require(pathToModule("YourFunction")
module.YOUFUNCNAMEHERE = function(Parameters)
print('Hello')
end
Now anytime you start using the module this function will be there and you will be able to use it.
Well thats how I do it at least :3
In the module script:
local module = {}
function module:SayHello()
print('Hello, World!')
end
function module:SayBye()
print('Goodbye, World!')
end
function module:SayWhatever(msg)
print(msg)
end
return module
In the other script:
local module = require(pathToModule)
module:SayHello() --> Hello, World
module:SayBye() --> Goodbye, World
module:SayWhatever("This is a printed message.") --> This is a printed message
Hope this helps!
2 Likes
Can i put these functions into a table?
Yeah, you can. Itβll work the same, but if you define a function without β:β it should be called with a β.β instead.
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.