What is “Good Code”? (in my opinion)
Writing good code typically means to write code that is clear and efficient for anyone to read as well as servers to run without lag and performance issues, I can suggest a few topics and tips which vary from easy to hard to implement and understand when writing code like:
[1] OOP (Object Orientated Programming / HARD)
this is a way more advanced topic when it comes to making things like Frameworks (a huge table of functions and events which are very well optimised and wrote that it makes adding new things to the game much easier instead of hard-coding everything… i learnt this lesson the hard way…) To sum this up: OOP is used when creating NEW but SIMILAR objects or data for your game this post helped me to understand what they are and why they’re overpowered when you learn them.
[2] Understanding When To Make A Function (Easy… ish)
one of the things i see people struggle with is making well-named and efficient functions, a-lot of people use Events and just hard-code the functions like so:
Event:Connect(function()
print("try and avoid this as much as you can")
end)
SOMETIMES, this is necessary in making certain things work but I would recommend breaking down functions into seperate things that you want your code to do, I’ll use a combat system example here:
local function DoubleJump() -- makes the player double jump
end
local function Block(enable) -- enables or disables blocking and runs all code involved with it
end
local function Sprint(enable) -- enables or disables sprinting and runs all code involved with it
end
local function GuardBroken() -- same thing as the Block and Sprint
end
local function Dash() -- again, same concept as the others
end
this is the best way (in my opinion) to write out functions and it allows for others and even future you to read and understand what things to WAY quicker than reading messy code.
NOTE
The code above would usually be split into separate Module Scripts which all get required from 1 central “Host” or “Main” script but again, that all comes down to how you want to organise things…
[3] Read Other Peoples Code & Break It Down To Yourself (EASY > HARD)
You said you want to learn how to code fighting games so research on YouTube & Forums the syntax and coding-approach that OTHER people have used to make their own combat systems or Battleground Games, do NOT just blindly watch YouTube tutorials and read code, you have to truly break down every line.
[4] Answering The Stone / Rock Question (HARD)
there are many developers out there who use Pre-Made modules that handle Rock spawning and other more tricky-to-make effects (Customisable Screen Shakers, Rock Debris, Voxel Destruction & Other Destruction Sytems) but if you relate to me in any way… you want to be able to write your own versions of these things which is great BUT… something like a Rock Debris spawner is HARD to make if you don’t understand more advanced math like Pi, Angles and other Geometry, I myself have never looked into making my own Rock spawner but I’ve read others code and they ALL use tricky math to calculate where the Rocks should be placed.
[5] Ragdolls (HARD)
typically, Ragdoll systems are made by creating an invisible part inside of every single body part of every players character and linking all body parts together with a Ball-Socket Constraint instead of a Motor6D when in the Ragdoll state (you can use Attributes for this), again, this is a bit more of a tricky creation but this video helped me out with understanding and even making my own Ragdoll system which I use in my current project.
Hopefully this shines some light on things you may be struggling with!