Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do I run a function from a module script as if it were being run from the same script?

Asked by 10 years ago

to make it clearer, I have a modulescript that returns a function when it's required. the main script (which is requiring the modulescript ) is supposed to run the function, but its running the function as if it were the modulescript running it. how would I fix that? sorry if this is confusing.

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

when creating a function in a module script, you have to put... i don't know how to explain it but look

old module

local module = {}

function jump() print "Jumping" end

return module

old server script

m = require (workspace.module)

m:jump

output

attempt to call method 'jump' (a nil value)

new module

local module = {}

function module:jump()-- I've added the value module and put a ":" and then the function print "Jumping" end

return module

server script

m = require (workspace.module)

m:jump-- code will now work

output Jumping

Ad

Answer this question