• Print

Author Topic: My first lua script is wrong  (Read 4517 times)

0 Members and 1 Guest are viewing this topic.

Offline Professor_Smiley

  • Newbie
  • *
  • Posts: 45
  • Karma: -24
My first lua script is wrong
« on: November 22, 2016, 11:46:26 am »
function Weaponz()
   if Player:IsAdmin() then
      Player:Give("weapon_mu_magnum")
      Player:Give("weapon_mu_knife")
      Player:Give("weapon_smg1")
   end
end

concommand.Add ( "weps", Weaponz )

[ERROR] lua/autorun/weaponz.lua:2: attempt to index global 'Player' (a function value)
  1. unknown - lua/autorun/weaponz.lua:2
   2. unknown - lua/includes/modules/concommand.lua:54

Help?

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: My first lua script is wrong
« Reply #1 on: November 22, 2016, 11:52:01 am »
In your case, you're using "Player" as an argument to a function that has no arguments. On the wiki, "give" has "Player:" before it because it expects a player, but in this it has no argument to pass. You said it's your first so I tried to explain it best I could.

Think of it this way:
Code: Lua
  1.  function FunctionName( Argument1, Argument2, ... ) -- Can have as many as needed
  2.     Argument1:Give( "class_name" )
  3. end
  4.  

Something like that. If it still doesn't make sense let me know.

Sent using Tapatalk. Owner of iViscosity Gaming.

I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Professor_Smiley

  • Newbie
  • *
  • Posts: 45
  • Karma: -24
Re: My first lua script is wrong
« Reply #2 on: November 22, 2016, 12:02:41 pm »
Okay thanks  ;D
Code: [Select]
function Weaponz( Player )
      if Player:IsAdmin() then
           Player:Give("weapon_mu_magnum")
           Player:Give("weapon_mu_knife")
           Player:Give("weapon_smg1")
      end
end

concommand.Add ( "weps", Weaponz )

This is what I have now, but it gives me more errors.

[ERROR] lua/autorun/muweapons.lua:3: attempt to call method 'Give' (a nil value)
  1. unknown - lua/autorun/muweapons.lua:3
   2. unknown - lua/includes/modules/concommand.lua:54

I tried adding Give in my arguments but it didnt fix the error. If Player:IsAdmin works then why not Player:Give?

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: My first lua script is wrong
« Reply #3 on: December 20, 2016, 06:23:40 am »
Hi,

May i ask if this script just runs serverside or also clientside or just clientside?
Cause Ply:Give() is an fully serverside function. If you want the script clientside you should work with the net libary. If you want I can give you an example for it.
« Last Edit: December 21, 2016, 11:59:27 pm by captain1342 »
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

  • Print