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

0 Members and 1 Guest are viewing this topic.

Offline Professor_Smiley

  • Newbie
  • *
  • Posts: 47
  • Karma: -24
    • View Profile
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

  • Hero Member
  • *****
  • Posts: 608
  • Karma: 25
    • View Profile
    • iViscosity Gaming
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 a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline Professor_Smiley

  • Newbie
  • *
  • Posts: 47
  • Karma: -24
    • View Profile
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

  • Jr. Member
  • **
  • Posts: 84
  • Karma: 3
    • View Profile
    • Aperture-Hosting
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-Hosting Manager

Web: https://Aperture-Hosting.de
Mail: Webmaster@Aperture-Hosting.de
Github: https://github.com/captain1242
Discord: https://discord.gg/wxpbtYk
Teamspeak: ts3.Aperture-Hosting.de
Support: https://www.aperture-hosting.de/ticketsystem/
"Hosting with Vision"