shared.lua:161: attempt to index global 'self' (a nil value)

Man I’m such a noob when it comes to lua errors :frowning:
Anyways, what does this mean, it’s the only thing preventing me from making my swep show up, and be finished.

So, can you post the code where the error happened?

“Self” is how you refer to the SWEP from inside one of its functions, like SWEP:PrimaryAttack. You probably tried to use self outside of a function.

[lua]
self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
local timescale = GetConVarNumber(“host_timescale”)
self.Weapon:EmitSound(“weapons/beagle/b.wav”, 100, timescale*100)
[/lua]

It happens at line 161, 162, and 163(line 1,2, and 3 as shown here)

Is this inside a function, floating around in nowhere, what?

Show the hole damn lua file please.

I think we should just not answer threads if they don’t follow this

http://www.facepunch.com/showthread.php?t=868561

Yeah, he expects help and doesn’t share his lua code which people are gonna download anyway.

You don’t need the hole code, and that’s where the error is, posting the full code won’t help.

You don’t have to post the whole code, but you at LEAST need to post the entire function that contains the error-ing lines. It’s best if you upload the whole thing to something like pastebin.com and paste the link with your request for help.

If your worry is that somebody will steal your code, I can guarantee you with 99% certainty that nobody will use your code.

They say imitation is the highest form of flattery, so if someone uses your code you should feel flattered.

Right, cause you’re the one asking for help and you would know better?

We need to see what sort of context these lines are in. A minimum would be the function that these lines are within. These lines could work or not work depending on where they are within a script.

It’s likely he stole it from another code, with the sort of beaver he is having now.

No, i do admit i looked at some lua codes to learn, but that was a long time ago, and i remembered that certain code and i’m using it in a swep im making. Now stop being a ass cubar. Also, i feel stupid, i didn’t even put it in a function, i just slapped it in there with no functions or anything, the problem should be solved now, time for testing

That’s fine, nobody gives a shit if you stole code the point of this forum is to help out with Lua problems, so just give us the code…

My problem is solved, it was because i didn’t put it in a function, and now it’s fine and works properly and comes up in my weapons menu. No more help is needed.