All this Script Module does is return the table that has a Metatable in it
-- Variables
local module = {}
local xp_lvl_DataStore = game:GetService('DataStoreService'):GetDataStore('xp/lvlStore')
-- Events
function module.XpLvlTable()
local xpLvlModuleTable = {}
local lvlControl = {
__call = function(xpToAdd,key,xpLvlTable)
-- Gets current lvl and xp
local curLvl = xpLvlTable[2]
local newXp = xpLvlTable[1] + xpToAdd
-- Checks if you lvled up
if curLvl == 0 and newXp >= 10 then
print('FIRST LVL UP')
local newXp = newXp - 10
-- Checks if can lvl up again
for i = curLvl,350 do
if i == 350 then
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,0)
table.remove(xpLvlTable,2)
table.insert(xpLvlTable,2,350)
elseif newXp - (10*i) < 0 then
-- Sets xp + lvl in the table then saves
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,newXp)
table.remove(xpLvlTable,2)
table.insert(xpLvlTable,2,i)
xp_lvl_DataStore:SetAsync(key,xpLvlTable)
break
else
newXp = newXp - (10*i)
end
end
elseif curLvl == 350 then
print('MAX LVL')
-- Sets xp + lvl in xpLvlTable then saves
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,0)
xp_lvl_DataStore:SetAsync(key,xpLvlTable)
elseif newXp >= 10*curLvl then
print('LVL UP')
-- Gets current lvl and xp
local curLvl = xpLvlTable[2]
local newXp = xpLvlTable[1] + xpToAdd
-- Checks if you lvled up
local newXp = newXp - 10*curLvl
-- Checks if can lvl up again
for i = curLvl,350 do
if i == 350 then
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,0)
table.remove(xpLvlTable,2)
table.insert(xpLvlTable,2,350)
elseif newXp - (10*i) < 0 then
-- Sets xp + lvl in the xpLvlTable then saves
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,newXp)
table.remove(xpLvlTable,2)
table.insert(xpLvlTable,2,i)
xp_lvl_DataStore:SetAsync(key,xpLvlTable)
break
else
newXp = newXp - (10*i)
end
end
else
print('NO LVL')
-- Sets xp then saves
table.remove(xpLvlTable,1)
table.insert(xpLvlTable,1,newXp)
xp_lvl_DataStore:SetAsync(key,xpLvlTable)
end
end
}
table.insert(xpLvlModuleTable,1,lvlControl)
return xpLvlModuleTable
end
return module
This is the Script that gets the error in line 21 "attempt to call local "xpLvlModuleTable" (a table value)"
-- Variables
local xp_lvl_DataStore = game:GetService('DataStoreService'):GetDataStore('xp/lvlStore')
local repStorage = game:GetService('ReplicatedStorage')
local serverScriptStore = game:GetService('ServerScriptService')
local xpChanger = repStorage:WaitForChild('Xp_LvlChanged')
local xpToAdd = 5
local part = script.Parent
local maxLvl = 350
local xp_LvlModule = require (serverScriptStore.Xp_LvlModule)
-- Events
local success,message = pcall (part.ClickDetector.MouseClick:Connect(function(plr)
-- Variables
local xpLvlModuleTable = xp_LvlModule.XpLvlTable()
local key = 'Player-'..plr.UserId
local xpLvlTable = xp_lvl_DataStore:GetAsync(key)
-- Fire to player
xpChanger:FireClient(plr,xpToAdd)
-- Gets table to save
print(xp_LvlModule.XpLvlTable())
xpLvlModuleTable(xpToAdd,key,xpLvlTable)
print('Xp: '..xpLvlTable[1]..' Lvl: '..xpLvlTable[2])
end))
