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.