'Attemped to call method of missing table' on Module Script

  1. What do you want to achieve?

So I’ve been working on transferring a lot of my client scripts onto modules to protect them. I have done this before when making a module inspired by fastcast.

  1. What is the issue?

When adding a function to be called in the module, the outliner gives me the error attempted to call missing method 'equiptWeapon' of table which if I correct means that they module can’t find this function in the table.

  1. What solutions have you tried so far?

I’ve have checked for an syntax errors or formatting errors with the table but can’t see anything.

I will send my code here if anyone wants to look into it.

Module Script Code

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local hud = player.PlayerGui:WaitForChild("Hud")
local RS = game:GetService("ReplicatedStorage")
local Animations = RS.Guns:FindFirstChild("Animations")
local camera = game.Workspace.CurrentCamera

local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local tweenservice = game:GetService("TweenService")


local Setup = {}



function Setup.new(inventory)
	
	local Inventory = inventory
	
	local aimCf = CFrame.new()
	local preSlot = nil
	local Map = false

	local canFocus = false
	local focus = nil

	local isAiming = false
	local Debounce = false

	local currentSway = 1
	local swayAmount = nil
	local aimSway = nil
	local swayCF = CFrame.new()
	local lastCamCF = CFrame.new()
	local Ragdoll = false
	
	local PreSlot = nil
	local frameWork = {}
	
	frameWork.Module = nil
	frameWork.ViewModel = nil
	frameWork.CurrentSlot = 1
	
	function frameWork:equiptWeapon(input)
		local slot = Inventory[input]
		local viewModelFolder = game.ReplicatedStorage.ViewModels
		local moduleFolder = game.ReplicatedStorage.Guns.Modules

		for i, v in pairs(camera:GetChildren()) do
			if v:IsA("Model") then
				v:Destroy()
			end
		end

		if moduleFolder:FindFirstChild(slot) then
			self.Module = require(moduleFolder:FindFirstChild(slot))

			--GunEvent:FireServer(input)

			if viewModelFolder:FindFirstChild(slot) then
				self.ViewModel = viewModelFolder:FindFirstChild(slot):Clone()
				self.ViewModel.Parent = camera
				swayAmount = self.Module.normSway
				aimSway = self.Module.aimSway
			end
		end
	end
	
	return frameWork
	
end

return Setup

Call of Module on client

local Table = {"ShanseiC44", "FireArm"}

local Framwork = require(game.Workspace.FrameWorkModual)
Framwork.new(Table)

Framwork:equiptWeapon(1)

If you need anymore information about my code or script let me know. Any help is much appriciated :smiley:

Because of the way you have your code setup, :equiptWeapon is a function in the return of Framwork.new(), rather than a function within the return of the require.

If you modify your code where you are trying to call the method to be something like this:

local Table = {"ShanseiC44", "FireArm"}

local Framwork = require(game.Workspace.FrameWorkModual).new(Table)    -- FrameWorkModule

Framwork:equiptWeapon(1)

it should no longer error

1 Like

I’m assuming you’re trying to create a class, because of the constructor “.new”. If that’s so, then what went wrong is how you’re using the constructor.

See, what you’re doing here is directly calling the constructor, without storing it, and when calling “equiptWeapon”, you’re trying to call it from the Module and not the new class you constructed. What you should do instead, is store the new constructed class in a variable (x = Framework.new) and call the method from the new variable (x:equiptWeapon). If you want to learn more about classes, just ask me, ill send a video

1 Like

I see what you mean now!

I also took not of what Seargent said as well but it makes sense now. So whenever i do this in future I need to always make sure to do is create and store the class when requiring the module.

Also feel free to send the video but thank you so much for the help :smiley:

This makes a lot of sense now. Thank you very much, so I just need to call the .new() class when requiring the module :smiley:

This video explains classes in detail. Check out his other videos as well, they’re really good

This is a video by the official roblox learn account, it’s also really good

I used both of these to learn classes and OOP

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.