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

Module script not working?

Asked by 8 years ago

I don't know why this isn't working, i'm trying to make the loop start when game is loaded.

local module = {}

local isLoaded = false

module.GameLoop = function()
    while wait() do
        if game:IsLoaded() == true then
            isLoaded = true
            print('Hello World')
        end
    end
end
module.GameLoop()

return module

2 answers

Log in to vote
0
Answered by 8 years ago

ModuleScripts do not run on their own. You could notice this by seeing that ModuleScripts do not have the disabled property of a Script and LocalScript. You can make a ModuleScript work by using the require function. Here's an example:

--In ModuleScript in workspace
local module = {}

module.TestFunc = function()
print("Hello from inside a ModuleScript!")
end

return module
--In Script in ServerScriptStorage

local mod = require(workspace.ModuleScriptName)
mod.TestFunc() --> "Hello from inside a ModuleScript!"

Here is a good resource to use when learning about ModuleScripts.

If I helped, please accept me as an answer, then we both get Reputation Points! :)

0
Thanks I already understand everything else about module scripts, I actually had an idea about the module script not working because it was being called in the same script but I didn't know about it very clearly. LifeInDevelopment 364 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

ModuleScript's do not run by themselves. You must make it run using a ServerScript or LocalScript. I'd recommend looking at this wiki article before you go on with ModuleScripts.

Answer this question