I have this question that has been flowing through my head recently. How do you start off a unique script? When you want to write a complicated script what’s the first thing you do?
Well usually I declare the variables then the functions then finishing touches but its up to you
--First, you need to have in mind that Programming is about logic
--you need to understand what you learned, it's kinda hard to explain but
--Right now i created a system where:
The player can equip a Weapon in Slot 1 or Slot 2
If the player click to equip in Slot 1 , the client will fire a RemoteEvent and will send information about:
The Type of weapon ["StringValue"]
The Id ["IntValue"]
Weapon name ["StringValue"]
so, with that small information i will:
Make the server check if what the [Client] sent to him has in their Data
For example:
i have a Table, and if something is missing or not equal....
then the server will decline, in exceptional ocasions, Ban the player
[ Why ban them... what if a player accidentally sent false information or wrong? ]
First, there is no way a legit player will
change values from a pre-made data that i created in a Local Script_
--See: The information that the [Client] sent to the server is Legit,
--but if any exploiter changed locally, it will send a changed value,
--and the server will notice that.
-- So.. we added some logic here, and the exploiter just did a big mistake
--that's why the server will ban the player]
First: you need to have alot of knowledge to create a complex script or something else, because if you don’t know how to make something that you are thinking then, probally you dind’t learned some concepts that would have helped you,
To create what i said [Above]
I needed to learn:
Remote Events
Table
[Module Scripts *just to make some things interesting]
understand how they work
++ i made the Slot system using a Gui to equip it
> you can do all that only using
> local VariableHere
> Use bool values, true, false,
> local function Here()
> Maths and Etc
it’s all about logic, but since i don’t want spam of Local in the same script i use Module and Tables…
there are alot of Things to learn, but if you understand the logic behind of what you want to create then, you can do it
_G.print = nil
Here you go amigo.
First thing I do is make all the variables at the top of the script.
I usally as well get some services since its better practice.
local ServerScript = game:GetService("ServerScriptService")
local RP = game:GetService("ReplicatedStorage")
local Ss = game:GetService("ServerStorage")
local part = workspace.Part
After that I get into the main Idea I want to do, slowly but surely adding code.
I usally do about 4 lines of code or more before I test anything out. But make sure to test out your code while scripting, you don’t want to do a lot of code and have too much errors to fix.
It as well depends on what you want to script, If your planning to script a whole system let’s say for example a combat system, you’ll need to use remote’s since your gonna be doing some things in the client and some other in the server. Whatever you do make sure to make most your values In the script like local debounce = 5
Instead of Instancing a IntValue since exploiters may be able to change that value if its not located properly.
In some other type of systems like @Moleza said you’ll need to use tables, perhaps metatables and we usally put those in modulescripts. you can make a module script and store any information you want. At first you might think a modulescript is useless but lets say that for example your making a simulator and you have lots of items. A modulescript is exactly what you need to use to store the items and be able to access them from other scripts without copy and pasting anything.
local module = {
commonSwords = {
["normalSword"] = {
damage = 1,
price = 0,
name = "Normal Sword"
},
["waterSword"] = {
damage = 3,
price = 150,
name = "Water Sword"
},
["fireSword"] = {
damage = 5,
price = 300,
name = "Fire Sword"
}
}
}
return module
and then you can easely access your data anywhere, Lets say I have a script and I want to get the damage of the fire sword it is a simple as this :
local ServerScript = game:GetService("ServerScriptService")
local modulescript = require(game.ServerScriptService.ModuleScript)
print(modulescript.commonSwords.fireSword.damage)
I always break bigger problems and break them into smaller ones. It’s a good software engineering practice to do this. It makes solving/creating big large complicated systems much easier.
In terms of scripting, this means writing out modular helper functions, then working your way to the final product. Planning is also a very good practice, even if you don’t write it out, just sit and think and look through some of the ways you can build a certain system or script.
Thank you! you and Mozela helped a lot!