![](/img/trans.png)
[英]lua - garry's mod - attempt to call global 'Player' (a table value)
[英]Garry's mod lua, attempt to call method error
我正在測試 Garry 的 Mod Lua 並且不斷彈出一個奇怪的錯誤
每當我使用任何 Glua 類時,似乎都會彈出此錯誤,例如 Player:kill
這是我的錯誤
[ERROR] lua/test.lua:6: attempt to call method 'Kill' (a nil value)
這是我正在使用的代碼
function killplayer()
local ply = LocalPlayer()
ply:Kill()
end
killplayer()
請幫忙
嘗試這個:
function killplayer()
if !(LocalPlayer() and LocalPlayer():Alive()) then return end
LocalPlayer():Kill()
end
你運行lua_openscript test.lua
嗎? 因為你必須在服務器端運行這個腳本,因為 Kill() 是 function 只在服務器端工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.