Nathan galler
Nathan galler

Reputation: 43

Garry's mod lua, attempt to call method error

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

Answers (2)

GlitchedLime
GlitchedLime

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

Try this:

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

Upvotes: 1

Related Questions