Creating gamemode functions that affect players/objects?

I’d like to make some convenience functions for a gamemode I’m starting but I’m not sure how to write them out in a way that will make them work or where to place them (shared.lua if I had to guess). The functions I’d like to make would work something like this

function GetCookies()
return ply.Cookies

function GiveCookies(num)
ply:GetCookies() + num

//and work like this


//ply now has 50 cookies

not sure how good of an example this is, but it’s the best I could think of.
The primary issue, I think, would be getting gmod to know what “ply” is (I mean in functions like PlayerSpawn() ply is already defined but I don’t know how to define “ply” in GiveCookies())

any suggestions?

local entMeta = FindMetaTable( 'Player' );
function entMeta:RocketMan( )
self:SetVelocity( Vector( 0, 0, 10000 ) )

for k,v in pairs( player.GetAll() )do

Thank you, but again, where do I place these functions so that they work globally?

If you insert it into the meta-table, it’ll be global for that realm. So if you made it SERVER only, it’ll work on the SERVER-side, but not the CLIENT-side. If you made it work on the CLIENT, it won’t work on the SERVER but will work on the CLIENT. If it’s in a shared file, it’ll be accessible on both the CLIENT and SERVER.

Here’s a little bit of information about loading files across realms:

Alright, thank you!