A function in computer programming can either do stuff or return stuff.
Imagine a function which plays some visual effect - this function only does stuff and doesn’t need a “return” at all.
playEffect()
print'effect played!'
Now imagine a function which gets a random player in your game.
It finds the player and returns it.
In your code you could implement it like this:
local player = getRandomPlayer()
player:Kick()
This code is supposed to kick a random player, so you create a function to find a player, and then you kick them.
getRandomPlayer needs to return this player, and after it returns, the value it returned is assigned to player
.
Then, once the value from the function is in the player
variable, you can kick the player.
Lua itself has a lot of functions which return something, for example tick()
.
local a = tick() -- a has the value returned by tick now