尝试在lua中索引一个空值

我有这段代码,

hook.Add( "PlayerSwitchWeapon", function( ply, oldWeapon, newWeapon )
    if (tostring(newWeapon) == tostring(hololink_swep) ) then
        print( "这个武器是特殊的" .. newWeapon:GetClass() .. "." );
    end
end );

当我执行它时,我得到了如下错误:

Error(s), warning(s): lua5.3: source_file.lua:1: 尝试索引一个空值 (全局变量'hoo') 堆栈回溯: source_file.lua:1: 在主要函数中 块 [C]: 在 ?

点赞
用户16234509
用户16234509

你需要把你的脚本放进特定的文件夹中,才能在游戏引擎中运行它们。我建议你把它们放到 garrysmod/addons/YOURADDONNAME/lua/autorun/serverclient 文件夹中,具体取决于你想做什么。你需要放哪些文件在什么位置,可以在这个链接的维基页面中详细了解。

2021-11-21 09:53:51