Method not working

Hello,
I am trying to do a system who add a new table into a table but clear the first table before adding a new table on it.

When i execute

require(game.ReplicatedStorage.Modules.Manangement).getPlayer(338411546):setCurrentAction("test",1)

this get me an error :

 23:05:17.081  Players.A12fluffy1.PlayerGui.Menu.StartMenu.Play.Script:4: attempt to call missing method 'setCurrentAction' of table  -  Serveur - Script:4
 23:05:17.081  Stack Begin  -  Studio
 23:05:17.081  Script 'Players.A12fluffy1.PlayerGui.Menu.StartMenu.Play.Script', Line 4  -  Studio - Script:4
 23:05:17.081  Stack End  -  Studio

I have tried to modify the command, edit the way to execute :setCurrentAction and it’s didn’t work.
To get help there is the full code :

Minimized full code
--[[
Game manager for Neighblox.

In frist, the manager will prepare tables and requirements
in second, it's will load needed data.
in last, it's get ready to be used to edit or add user's data such as money, playtime, job and etc.

]]--

--[[
	____  __________  __  __________  ________  __________   _____________
   / __ \/ ____/ __ \/ / / /  _/ __ \/ ____/  |/  / ____/ | / /_  __/ ___/
  / /_/ / __/ / / / / / / // // /_/ / __/ / /|_/ / __/ /  |/ / / /  \__ \ 
 / _, _/ /___/ /_/ / /_/ // // _, _/ /___/ /  / / /___/ /|  / / /  ___/ / 
/_/ |_/_____/\___\_\____/___/_/ |_/_____/_/  /_/_____/_/ |_/ /_/  /____/  

]]--

-- Services
local LocalizationService = game:GetService("LocalizationService")
local MarketPlaceService = game:GetService("MarketplaceService")
local UserInputService = game:GetService("UserInputService")
local GamePasseService = game:GetService("GamePassService")
local RunService = game:GetService("RunService")
local TextService = game:GetService("TextService")
local StarterGui = game:GetService("StarterGui")
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")

-- Modules
local Manager = script
local PlayerData = require(Manager.Elements.PlayerData)
local GoodSignal = require(Manager.Packages.GoodSignal)

-- Instances
local Plots = game.Workspace:WaitForChild("Plots", 3000)



-- MODULE START --
local Management = {}
Management.__Index = Management


-- Table (Data)
local PlayersDict = {}

-- Assets
Management.PlayersDictionary = PlayersDict

-- LOCAL FUNCTIONS --

local function translateAction(value)
	
	return
end

--[[
    ________  ___   ______________________  _   _______
   / ____/ / / / | / / ____/_  __/  _/ __ \/ | / / ___/
  / /_  / / / /  |/ / /     / /  / // / / /  |/ /\__ \ 
 / __/ / /_/ / /|  / /___  / / _/ // /_/ / /|  /___/ / 
/_/    \____/_/ |_/\____/ /_/ /___/\____/_/ |_//____/  

]]--


-- Get functions

function Management.getPlayer(UID) -- get a player by his UID.
	local match = Management.PlayersDictionary[UID]
	if match then
		return match
	else
		error('Player ( '.. UID .. ' ) has not been founded.')
	end
end


-- Default

function Management.PlayerAdd(Player: Player) -- Add the player, his data and prepare the player.
	local PlayerUI = Player:WaitForChild("PlayerGui")
	
	-- GET READY TABLES --
	if not (Player.UserId == 338411546) or not (Player:GetRankInGroup(8804274) >= 246 )then -- Developement safety protection.
		Player:Kick("Not allowed to join at the moment.")
	end
	
	
	local self = {}
	setmetatable(self, Management)
	PlayersDict[Player.UserId] = self -- Attach the table to player's UID.
	
	self.UID = Player.UserId -- Set the UID to the table.
	self.effects = {} -- Prepare the table of effects.
	self.demands = {} -- Prepare the table of demands.
	self.actions = {} -- Prepare the table of actions.
	self.job = nil -- Prepare job value.
	self.plot = nil -- Prepare plot value.
	
	-- LOAD --
	local Prompter = require(PlayerUI.MessagePrompt.Prompter)
	
	local success, message = pcall(function() -- Protection to prevent data loss.
		
		task.spawn(function() -- Load the player's money/currency.
			if PlayerData.Load(Player, "playtime") == 0 or PlayerData.Load(Player, "playtime") == nil then
				self.money = 2500
			else
				self.money = PlayerData.Load(Player, "money")
			end
		end)
		
		task.spawn(function() -- Load the player's playtime.
			if PlayerData.Load(Player, "playtime") == nil then
				self.playtime = 0
			else
				self.playtime = PlayerData.Load(Player, "playtime")
			end
		end)
		
		task.spawn(function() -- Load the player's emotions.
			if PlayerData.Load(Player, "emotion") == nil then
				self.emotion = "neutral"
			else
				self.emotion = PlayerData.Load(Player, "emotion")
			end
		end)
		
		task.spawn(function() -- Load the player's effects.
			table.clear(self.effects)
			if not ( PlayerData.Load(Player, "effect") == nil ) then
				self.effects = PlayerData.Load(Player, "effect")
			end
		end)
		
		task.defer(function() -- Check if the player has joined for the first time.
			if self.playtime == 0 then 
				Prompter.Prompt("Ok", "Message", "\nWelcome to Neighblox.\nto understand how this game work, please follow the first steps.", "tuto")
				PlayerUI.UICommunicationClientServer:FireClient(Player, "tutorial")
			end
		end)
	end)
	
	if not success then -- Verify if the player's data has loaded.
		PlayerUI.UICommunicationClientServer:FireServer(Player, "FailedToLoadPlayerData")
		wait(3)
		Player:Kick("Your data has failed to load.")
	end
	
	task.spawn(function() -- Set the player's plot.
		local Occupied = false
		--if not (MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 784646874)) then
			local PlotNumber = 0
			
			repeat
				PlotNumber = math.random(1, 16)
				if Plots:FindFirstChild("Plot_".. PlotNumber).Occupied.Value == true then
					Occupied = true
				else
					Occupied = false
					self.plot = PlotNumber
				end
				
			until not Occupied
		--end
	end)
	
	task.defer(function() -- Wait everything is ready.
		PlayerUI.UICommunicationClientServer:FireClient(Player, "ShowMenu")
		
		task.spawn(function() -- Automatic playtime.
			RunService.Heartbeat:Connect(function() -- Run service heartbeat.
				self.playtime += 1 -- Add a second every second.
				wait(1)
			end)
		end)
	
		task.spawn(function() -- Automatic status ( demands ).
			RunService.Heartbeat:Connect(function()
				wait()
			end)
		end)
	end)
	
	return self 
end


-- Function (set) reset the data and set a new one.

function Management:setJob(text) -- Reset and set the player's job.
	self.job = text
	return self
end

function Management:setCurrentAction(text, Multiplier) -- Reset and set the player's current action.
	table.clear(self.actions)
	table.insert(self.actions, {text, Multiplier})
	print(self.actions)
	return self
end

function Management:setMoney(int) -- Reset and set the player's money.
	self.money = int
	return self
end

function Management:setPlot(int) -- Set the player's plot.
	self.plot = int
	return self
end

function Management:setEmotions(text) -- Set the player emotion.
	self.emotion = text
	return self
end

function Management:setEffect(text) -- Reset and set a new effect.
	table.clear(self.effects) 
	table.insert(self.effects, text)
	return self
end


-- Function (add) add a data to the current data.

function Management:addMoney(int) -- Add money to the player.
	self.money += int
	return self
end

function Management:addEffect(text) -- Add an effect to the player.
	table.insert(self.effects, text)
	return self
end

function Management:addAction(text, Multiplier)
	table.insert(self.actions, text.. "_" ..Multiplier)
	return self
end

return Management

Could someone help me to solve the problem because i don’t understand why it is not working right now.
Thanks you again.

Some functions ares empty it is normal i didn’t complet them because they need the :setCurrentAction to work before.

It seems to be an issue with the module itself. Could you provide the code of the Management Module?

Based on the error, I’m assuming you just forgot to add it to the table

yea i already put the module code in

My apologies, I thought it was the code you provided. The issue is that the function setCurrentAction is part of the management table not the player table.

Whereas, based on your code snippet, I believe its supposed to be self:setCurrentAction, in the addPlayer function.

1 Like

I see what you mean but the code doesn’t work like this in this case,
self is used as a temporary table and PlayerDict is also a temp table but Management.PlayersDictionary is not a temp table that means when in AddPlayer

and before AddPlayer

are executed, that automaticaly save the table into the server even modifications are saved correctly.
And so this function :

Get the player saved into Management.PlayersDictionary and return the “self” to edit it, like you can get values by using ( in a script for exemple ) manager.Plot it’s will get you the data saved into self.plot which the previous function: “getPlayer” has founded on the Player Dictionary.

So function Management:setCurrentAction(text, Multiplier) is properly written and does not make the problem same as all others functions are working correctly.

1 Like

Ok nevermind, i have tried to execute every functions i get the same error, the problem for me cannot be using Management:[function] instead of self:[function] ( or self.[function] )

The error which is

attempt to call missing method '[AnyFunctions]' of table

Actually the module script is using the same method as TopBarPlus

Here’s an exemple of TopBarPlus function.

function Icon:setEnabled(bool)
	self.isEnabled = bool
	self.widget.Visible = bool
	self:updateParent()
	return self
end

I Even tried the same method on a other module and it’s was working

Secondary code as exemple
-- Services
local Players = game:GetService("Players")

-- References
local module = script
local Package = module.Package
local Templates = module.Templates
local Player = Players.LocalPlayer

-- Modules
local Utility = require(Package.Utility)

-- Script
local Settings = {}
Settings.__index = Settings

-- Lists
local iconsDict = {}

-- Variables
Settings.iconsDictionary = iconsDict

-- Local
local totalCreatedIcons = 0

-- Functions
function Settings.getSettings() -- Get all settings
	return Settings.iconsDictionary
end

function Settings.getSettingByUID(UID) -- Get setting by UID
	local match = Settings.iconsDictionary[UID]
	if match then
		return match
	end
end

function Settings.getSetting(nameOrUID) -- Get setting by name or UID
	local match = Settings.getSettingByUID(nameOrUID)
	if match then
		return match
	end
	for _, setting in pairs(iconsDict) do
		if setting.name == nameOrUID then
			return setting
		end
	end
end

function Settings.new() -- Create a new setting
	local self = {}
	setmetatable(self, Settings)
	
	local iconUID = Utility.generateUID()
	iconsDict[iconUID] = self
	
	self.player = Player
	self.module = module
	self.UID = iconUID
	self.isEnabled = true
	self.creationDate = os.clock()
	self.dropdown = {}
	
	local widget = require(Package.Widget)(self)
	self.widget = widget
	
	totalCreatedIcons += 1
	local ourOrder = totalCreatedIcons
	self:setOrder(ourOrder)
end

function Settings:setTitle(Title: string)
	self.Title = Title
	return self
end

function Settings:setName(Name: string)
	self.Name = Name
	return self
end

function Settings:setType(Type: "Button" | "DropDown" | "Selector" | "Slider")
	self.Type = Type
	return self
end

function Settings:setOrder(Order: number)
	self.Order = Order
	return self
end

function Settings:setEnabled(Boolean: boolean)
	self.isEnabled = Boolean
	return self
end

return Settings

I Didn’t gived the context execution, everything is executed as server not in local script.

The index metamethod key needs to be lowercase.

In your code, it’s set like this:

Management.__Index = Management

Try this instead:

Management.__index = Management
1 Like

Ah good idea, but actually it is 1 AM in France, I will try it later.

it is working correctly thanks you, it was not easy to see.