Beginner coder asking for some feedback

Hey guys. I’m just getting into coding, and I’ve set my first project as a simple RTD script for a server my friend is starting. I have a couple mindbogglingly simple questions regarding the code that I couldnt find specific answers to online. As such, any feedback would be appreciated.

If I’m wanting to set variables that can be edited via console commands, such as the duration of certain rolls, would this be adequate?

local duration = CreateConVar("rtd_example_duration", 15)
local duration = duration:GetInt()

By my knowledge, that would create the variable duration, isolated to the lua file it is present in, and it would give it the default value of 15 and assign it permanently to be an integer? Since I have already assigned it as the integer 15, is it then redundant to put the second line? Next, when it comes to actually testing the script, could I simply add this to the folder housing the init.lua and expect the script to run?

There’s a lot more complicated stuff I’d like to have some input on, such as the extended roll function and the actual method table, but I don’t wish to bog down the forums with an entire .lua file for you guys to examine, since most of, if not all of it is intricately connected. However if anyone willingly wants to help look over the entire file, I’d gladly reply to any PMs.


Remove that second line. You should be using duration:GetInt() everywhere you need the duration. If you save the int in a variable, the variable won’t be accurate, because when the cvar changes, the variable will stay the same.

Remove the second line, and as an example, if I were to setup a timer I would then reuse the GetInt like this?

local duration = CreateConVar("rtd_example_duration", 15)

timer.Simple(duration:GetInt(), functionExample)

Thanks for the fast reply.

Yep. You got it.