Error: Missing Method In ModuleScript

Hello there,

I am currently in the process of making a grid-based placement system, and have run into an interesting error. Any help would be greatly appreciated!

Error:

  20:00:40.946  Players.CadenDevelops.PlayerGui.BuildMode.PlacementSystemV2:18: attempt to call missing method 'activate' of table  -  Client - PlacementSystemV2:18

ModuleScript:

-- SERVICES
local players = game:GetService("Players")
local runService = game:GetService("RunService")


-- GENERAL VARS
local plr = players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()


-- SETTINGS

-- BOOLS
local interrpolation = true
local moveByGrid = true
local buildModePlacement = true


-- INTS
local rotationStep = 90


-- FLOATS
lerpSpeed = 0.7


-- OTHER
local gridTexture = ""


local placement = {}


-- CONSTRUCT VARS
local gridSize
local itemLocation
local rotateKey
local terminateKey

-- ACTIVATION VARS
local object
local placedObjects
local plot
local stackable

-- POSITION VARS
local posX
local posY
local posZ



local function approvePlacement()
    return true
end

local function snap(x)
    return math.floor((x/gridSize)+0.5)*gridSize
end

local function calculateYPosition()

end

local function calculateItemPosition()
    if moveByGrid then
        posX = snap(mouse.Hit.X)
        posY = mouse.Hit.Y
        posZ = snap(mouse.Hit.Z)
    else
        posX = mouse.Hit.X
        posY = mouse.Hit.Y
        posZ = mouse.Hit.Z
    end
end

local function translateObj()
    if placedObjects and object.Parent == placedObjects then
        calculateItemPosition()

        object:PivotTo(CFrame.new(posX,posY,posZ))
    end
end


-- CONSTRUCT FUNCTION
function placement.new(g,objs,r,t)
    local data = {}
    local metaData = setmetatable(data,placement)
    
    gridSize = g
    itemLocation = objs
    rotateKey = r
    terminateKey = t
    
    data.grid = gridSize
    data.itemlocation = itemLocation
    data.rotatekey = rotateKey
    data.terminatekey = terminateKey
    
    return data
end

function placement:activate(id,pObjs,plt,stk)
    object = itemLocation:FindFirstChild(id):Clone()
    placedObjects = pObjs
    plot = plt
    stackable = stk
    
    if not approvePlacement() then
        return "Placement could not activate!"
    end
    
    if not stackable then
        mouse.TargetFilter = placedObjects
    else
        mouse.TargetFilter = object
    end
    
    object.Parent = placedObjects
end

runService:BindToRenderStep("Input",Enum.RenderPriority.Input.Value,translateObj)

return placement

Localscript:

-- SERVICES
local replicatedStorage = game:GetService("ReplicatedStorage")


-- MODULES
local placementModule = require(replicatedStorage.ReplicatedModules.PlacementHandler)


-- MAIN
local placement = placementModule.new(4,replicatedStorage.Assets.Objects,Enum.KeyCode.RightShift,Enum.KeyCode.Z)

wait(2)

placement:activate("Birck Wall 1",workspace.Stores.Store1.Objects,workspace.Baseplate,false)

Thank you in advance!

I could not find an :activate in the documentation.

What is this line:

function placement:activate(id,pObjs,plt,stk)

It seems to be the problem.

That is supposed to be a function that I can invoke form the client script. If I was to change it to placement.Activate(), would that work?

1 Like

For anyone reading this thread in the future, i solved this issue by adding the following line below the definition of the placement module.

placement.__index = placement
2 Likes

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