Global Variable

How do you make a variable that can be used on another function?

Eg. a kill combo counter?

I am using this so when you get 3 in a row kills you get a chance to get an RPG.

Variables in Lua are global by default.

Wait what?

So how do i define one?

global combonumber = combonumber + 1


No, you don’t need any type thing in front.

Variable = 20

Global variable:
[lua]Randomvariable = Randomvariable + 2[/lua]

Local variable:

[lua]local Randomvariable = Randomvariable + 2[/lua]


can you store an Ent in there for exapmple


Randomvariable = ply

Ah, how would I make a combo counter?

For a player.
You know how many kill’s until death in a game mode?

ply:Frag I think… Not sure…

You can store entitys in variables. You would also use player:Frags() and player:Deaths()

You can also do this :

[lua]local Meta = FindMetaTable(“Player”)

function Meta:GetCombo()
if self.Combo then
return self.Combo
return 0

function Meta:ChangeComboCounter(points)
self.Combo = points + self:GetCombo()

local ply = player.GetByID(1)

print(ply:GetCombo()) // Prints 0
print(ply:GetCombo()) // Prints 34[/lua]