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

Am I doing something wrong with this ModuleScript?

Asked by 8 years ago

I am trying to experiment with ModuleScript's, I'm trying to make it print the name of every-thing in TestFolder but so far I am having problem's with this script. Can anyone tell me what I am doing wrong?

Server Script code:

script.Parent.MouseButton1Click:connect(function()
    local module = game.ReplicatedStorage.Modules.TestingModule
    module:GetChildren()
end)

ModuleScript code:

local module = {}

function module:GetChildren()
    for i,v in pairs(game.ReplicatedStorage.TestFolder:GetChildren()) do
        print(v.Name)
    end
end

return module

Output:

GetChildren is not a valid member of ModuleScript

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

Very simply, you forgot to require the ModuleScript:

script.Parent.MouseButton1Click:connect(function()
    local module = require(game.ReplicatedStorage.Modules.TestingModule)
    module:GetChildren()
end)
0
Thanks. ISellCows 2 — 8y
Ad

Answer this question