Reputation: 43
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!
Upvotes: 1
Views: 2387
Reputation: 1
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.
Upvotes: 0
Reputation: 86
Try this:
function killplayer()
if !(LocalPlayer() and LocalPlayer():Alive()) then return end
LocalPlayer():Kill()
end
Upvotes: 1