Hey guys this is my first time posting soo....
Anyways, I was testing my gamemode and when I tested it online my friend keep getting this message
[QUOTE]attempt to call method 'GetPrintName' (a nil value)[/QUOTE]
So i'm guessing this code is creating the error.
[QUOTE]local weapon = LocalPlayer():GetActiveWeapon():GetPrintName()[/QUOTE]
I'm new and this is my first time coding, so i'm probably doing something wrong.
Make sure it's in if CLIENT tags, it is a client-only method
Usage example would be this.
[img]http://puu.sh/3qQ5W.jpg[/img]
I keep getting the same error, here are some pics of my code and my error
Here's my code
[img]http://i.imgur.com/cub3SaR.png[/img]
Here's my error whenever someone dies
[img]http://i.imgur.com/aKk9pzB.jpg[/img]
[QUOTE=BolONYz;41257951]Here's my error whenever someone dies[/QUOTE]
I believe if someone is dead then they won't have an active weapon, so you can't get the name from it.
Check if they are alive (or if they actually have a weapon).
Something like
[code]local weapon = LocalPlayer():Alive() and LocalPlayer():GetActiveWeapon() and LocalPlayer:GetActiveWeapon():GetPrintName() or "No weapon"[/code]
The alive check isn't really needed if you are also checking if the weapon is valid, it could just be
[code]local weapon = LocalPlayer():GetActiveWeapon() and LocalPlayer:GetActiveWeapon():GetPrintName() or "No weapon"[/code]
[QUOTE=wh1t3rabbit;41258230]
The alive check isn't really needed if you are also checking if the weapon is valid, it could just be
[code]local weapon = LocalPlayer():GetActiveWeapon() and LocalPlayer:GetActiveWeapon():GetPrintName() or "No weapon"[/code][/QUOTE]
You forgot brackets
[code]local weapon = LocalPlayer():Alive() and LocalPlayer():GetActiveWeapon() and LocalPlayer():GetActiveWeapon():GetPrintName() or "No weapon"[/code]
[QUOTE=wh1t3rabbit;41258230]I believe if someone is dead then they won't have an active weapon, so you can't get the name from it. [/QUOTE]
Thanks, fixed it with this code
[CODE]
if LocalPlayer():GetActiveWeapon():IsWeapon() then
draw.SimpleText(LocalPlayer():GetActiveWeapon():GetPrintName(), "Trebuchet24", 12, ScrH() - 95, Color(255,255,255,255))
else
draw.SimpleText("No Weapon", "Trebuchet24", 12, ScrH() - 95, Color(255,255,255,255))
end
[/CODE]
Sorry, you need to Log In to post a reply to this thread.