1
votes

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!

1

1 Answers

1
votes

Try this:

function killplayer()
  if !(LocalPlayer() and LocalPlayer():Alive()) then return end
  LocalPlayer():Kill()
end