you cut something out, because 6th line erroring doesn’t have any sense.
And this error happens because you haven’t listened to us, the ActiveWeapon was a NULL, which means you didn’t have any IsValid check.
We can’t help you, if you simply don’t listen to us. You may think you don’t need something, and cut it out, but again, you’re the one asking for help - and we are just helping you.
[editline]2nd September 2017[/editline]
I’m going to post full code here, hopefully it works. I am also going to add comments, so hopefully you learn something
local function plydisco(ply) --Here, we define, create a local function - Local functions exist only in the same file as it is created in
local ActiveWeapon = ply:GetActiveWeapon() -- We are defining a new variable which contains player held weapon, note: the ActiveWeapon can be empty if the player doesn't have any weapon - again, we're making it local - no need to make it globally available.
if ( IsValid(ActiveWeapon) and ActiveWeapon:GetClass() == "guigui_handcuffed" ) then --We are checking here, if the variable (with the weapon) is valid, and if the class of the weapon equals something
RunConsoleCommand("ulx ban",ply:Name(),"You got punished for leaving while being cuffed","1d") --self explanatory, the wiki states that we need to pass each argument as new string
PrintMessage( HUD_PRINTTALK, ply:Name().. " got fucking rekt." ) --You seem to get that, good for you
PrintMessage( HUD_PRINTTALK, ply:Name().. " left the game." )
hook.Add("PlayerDisconnected","PunishLeavers",plydisco) --We are "sticking" that function we just made using existing in game hook system - this makes it that whenever there's an event happening in the game, the original function will call those "hooks", allowing us to add on our own behavior to those events. First argument is the event name. You can see all of them on gmod wiki. Second argument is our unique name, in case we ever need to remove that hook. Third argument is our function callback, so whenever this event gets run, that function that we supplied will be run as well. Since we are referencing to the function (it is different than calling it or creating it) we don't add the ()'s around them. Hook arguments like Player get automatically passed over to our function.