if statement not working

Pseudo code:

Level = 0

Function got kill
Print got kill
Level == level +1

If (level==1)
Give weapon
Give ammo

The if statement just doesn’t check if level = 1 I’ve even got a kill and it prints that level is 1

Well firstly there’s no ‘then’ after the if. Lua is also case sensitive so Level and level are seen as different variables. That function also won’t work since you’re doing level == whatever instead of level = whatever. Make sure to use code tags.

Don’t forget that == is an operator which compares the 2 values, whereas a single = sets a value on the variable. For example, in the part “level == level +1”, you should do “level = level +1” instead, as the == does nothing there, just trying to compare them.

It’s best to just post the real code instead of pseudo, so that we can actually fix it and then you can see what is different.

If the code was slightly less pseudo-

Level = 0 //Make sure to localize this if it won't be used in other scripts

function GotKill() //Make sure to localize this as well if it won't be used in other scripts
print("Got kill!")
Level = Level+1

if (Level == 1) then //I suggest putting this in the GotKill function if you need it to be checked whenever it is run
Give weapon
Give ammo

Note that Give weapon and Give ammo would actually have to be functions.

Let’s say you have: local level = 0

then you could have a function named Levels then hook a playerdeath hook to that function then inside of said function check if the player is valid and player didnt commit suicide, if they didnt and everything is good, do add a level to their player by doing ply.level = ply.level + 1

Here is a working(hopefully code, wrote it in facepunch reply thing)

local level = 0

function lol( victim, inflictor, attacker )

if ( IsValid( victim ) && victim != attacker ) then

attacker.level = attacker.level + 1

print( attacker:Name() … " is now " … attacker.level )

hook.Add( “PlayerDeath”, “asd”, lol )