如何解决“尝试调用方法'addMoney'(nil值)"错误? [英] How to fix 'attempt to call method 'addMoney' (a nil value)' error?
本文介绍了如何解决“尝试调用方法'addMoney'(nil值)"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个.lua文件,一个文件名为sv_money.lua,另一个文件名为Economy.lua
I have two .lua file, one named sv_money.lua and the other economy.lua
sv_money.lua 中的代码是:
The code in sv_money.lua is :
local meta = FindMetaTable("Player")
local PlayersMoney = {}
function meta:addMoney(amount)
if not amount then return false end
PlayersMoney[self:SteamID64()] = PlayersMoney[self:SteamID64()] + amount
end
在经济方面.lua:
for k, v in pairs(player.GetAll()) do
v:addMoney(60)
Notify(v, "You've received 60€.", 5, "Generic" )
end
预期结果是播放器屏幕上的通知您已收到...",但实际结果是错误:
The expected result is the notification "You've received..." on players screen but the actual result is the error :
Lua Error: [ERROR] addons/economy/lua/autorun/economy.lua:63: attempt to call method 'addMoney' (a nil value)
1. unknown - addons/economy/lua/autorun/economy.lua:63
出于我未知的原因,此代码在Economy.lua中起作用:
For an unknown reason to me this code in economy.lua works :
hook.Add("PlayerSpawnProp", "Cost", function(ply, class)
if not ply:canAfford(10) then
Notify(ply, "You don't have enough money !", 5, "Error" )
return false
else
Notify(ply, "You've spent 10€ to spawn this prop.", 5, "Generic" )
ply:addMoney(-10)
return true
end
end)
推荐答案
问题是,经济性.lua是在客户端执行的,而我的代码是在服务器端执行的.
The problem was that economy.lua was executed client-side while my code was for server-side.
这篇关于如何解决“尝试调用方法'addMoney'(nil值)"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文