I am testing out Garry's Mod Lua And a strange error keeps poping up
This error seems to be popping up whenever i use any Glua classes, Such as Player:kill
this is my error
[ERROR] lua/test.lua:6: attempt to call method 'Kill' (a nil value)
And here is the code i am using
function killplayer()
local ply = LocalPlayer()
ply:Kill()
end
killplayer()
Please help
Try this:
function killplayer()
if !(LocalPlayer() and LocalPlayer():Alive()) then return end
LocalPlayer():Kill()
end
Did you run lua_openscript test.lua
? Because you have to run this script on server side, because Kill() is function working only on server side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.