2 questions; function won't do arithmetic and need to announce lvl up.

Hey guys, I seem to be having a problem with my gamemode which is halting it’s production :\ I keep getting an error that says it can’t do an arithmetic. To be honest I don’t know if I’m even doing it correctly…

[lua]
function endmatch2players( victim,killer, ply )
if OPT_FIGHT > 0 and victim:Team() == 2 then OPT_FIGHT = 0 – checking if the player who died was actually
MATCH_STARTED = 0 – fighting.
killer.Exp = killer.Exp + 50
killer.Winst = killer.Winst + 1
killer.Money = killer.Money + 250
victim.Winst = 0
victim.Opted = 0
killer.Opted = 0
victim.Boxer = 0
killer.Boxer = 0
killer:StripWeapons()
if MATCH_STARTED == 0 then victim:SetTeam(1) end
if MATCH_STARTED == 0 then killer:SetTeam(1) end
PrintMessage( HUD_PRINTTALK, "[Alert]: " … victim:GetName() … " Lost the match to “…killer:GetName()…” Theres now more spots open for a match! " )
if killer.Winst > 1 then PrintMessage( HUD_PRINTTALK, “[Alert]: “…killer:GetName()…” is now on a winstreak of “…killer.Winst…”!”) end
end
end
[/lua]

Also, some of this hasn’t been tested in about… a month because I haven’t had a computer that has access to Notepad++ nor gmod…

Now, onto the second question - when a player levels up how would I get it to announce it just once and at that time only.

Part 1. The error is probably due to trying to use one of the victim. or killer. values which has not been set yet, add a check to see if the value is nil if it is set it a staring value like 0 or 100 or something.
Part 2. There are several ways to do this, if you don’t want to be fancy you could use ply:ChatPrint(“You leveled up!!”) or you could create a usermessage hook on the client and send the information about the level up that way and then display a fancy level up screen.

Nah dude, I have a function set already as a test to see what your exp and money is, it comes back exactly with what I have.

ok, then what the exact error you get and what line is it on, and which line of the code you posted is that?

There is not enough information to help, because the error you posted is usually because you are trying to perform some kind of math on a non number, so either a nil, a string, a vector, an angle, etc. And the only thing I see in that snipet of code is those values not being checked, and even if you test it if you misplaced a local or added a capital letter where it doesn’t belong then you have a nil.

The error is most likely caused here
[lua]
killer.Exp = killer.Exp + 50
killer.Winst = killer.Winst + 1
killer.Money = killer.Money + 250
[/lua]

If the value of killer.Exp is nil you cant add to it and it will throw out an error like
input:1: attempt to perform arithmetic on global ‘killer.Exp’ (a nil value)
You need to initialize it by setting it to 0 before you start adding to it to fix this

I’ll see if it works in a little while seeing as I have no computer, but thanks guys, I appreciate it! :slight_smile: