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

Why is this modular function returning as nil?

EDIT: FIXED OVER COMMUNITY CHAT

Hi,

I'm quite new to using OOP and furthermore using module scripts.

I've come across an issue whilst using my module script, that when the script requires a function, the output spits out an error claiming the function is nil.

This is likely a stupid mistake, however it is getting on my nerves as to why it is occurring.

Module Script:

local module = {}

  

local MTP_Trousers='rbxassetid://2414240168'

local MTP_BR=''

local MTP_LG=''

local MTP_RLC=''

local MTP_GPP=''

  

local MTPChange=function(Plr,Type,Rank)

if not Plr.Character:FindFirstChild("Shirt") then

local SNew=Instance.new("Shirt",Plr.Character)

SNew.Name="Shirt"

end

if not Plr.Character:FindFirstChild("Pants") then

local PNew=Instance.new("Pants",Plr.Character)

PNew.Name="Pants"

end

if not Plr.Character:FindFirstChild("ShirtGraphic") then

local SGNew=Instance.new("ShirtGraphic",Plr.Character)

end

wait()

if Type=='MTP_BR' then

Plr.Character.Shirt.ShirtTemplate=MTP_BR

Plr.Character.Pants.PantsTemplate=MTP_Trousers

elseif Type=='MTP_LG' then

Plr.Character.Shirt.ShirtTemplate=MTP_LG

Plr.Character.Pants.PantsTemplate=MTP_Trousers

elseif Type=='MTP_RLC' then

Plr.Character.Shirt.ShirtTemplate=MTP_RLC

Plr.Character.Pants.PantsTemplate=MTP_Trousers

elseif Type=='MTP_GPP' then

Plr.Character.Shirt.ShirtTemplate=MTP_GPP

Plr.Character.Pants.PantsTemplate=MTP_Trousers

end

end

  

return module

Server Script

local QMModule=require(script.Parent.Quartermaster_Module)

local QMEvent=game.ReplicatedStorage.Events.QM_Event

  

QMEvent.OnServerEvent:Connect(function(Plr,Type)

if Type=='MTP_BR' or Type=='MTP_LG' or Type=='MTP_RLC' or Type=='MTP_GPP' then

local Rank=Plr:GetRankInGroup(1197640)

QMModule.MTPChange(Plr,Type,Rank)

end

end)

1 answer

✓ Accepted answer

You need to actually link the function with the module.

--Module Script
local module = {}

module.MTPChange = function(Plr,Type,Rank)
    
end

return module

--Server Script
local module = require(moduleObj)
module.MTPChange()

Or you could just return the function

--Module Script
local MTPChange = function(Plr,Type,Rank)
    
end

return MTPChange

--Server Script
local MTPChange = require(moduleObj)
MTPChange()

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