How did scripters manage to create such advance scripts?

Scripting is awesome and powerful, the only painful part in it is how you are able to create one that is advanced through sophisticated and intricate thinking. Here’s an example of a camera bobbling effect script made by Roblox.

local RunService = game:GetService("RunService")

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function updateBobbleEffect()
	local now = tick()
	if humanoid.MoveDirection.Magnitude > 0 then -- Is the character walking?
		local velocity = humanoid.RootPart.Velocity
		local bobble_X = math.cos(now * 9) / 5
		local bobble_Y = math.abs(math.sin(now * 12)) / 5

		local bobble =, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
		-- Scale down the CameraOffset so that it shifts back to its regular position.
		humanoid.CameraOffset = humanoid.CameraOffset * 0.75


Yeah it seems complicated, but the part I am most attracted to is the function updateBobbleEffect(). My question is, how did such scripters manage to know the math and science behind this to create a good bobbling effect?

Another great script I have discovered is AI bots which can be found in the Toolbox. The most interesting part in the script is the part where it computes the path. Although the general idea of computing one should be easy to understand, this script, however, is an exception:

while wait() do
	local enemytorso = GetTorso(hroot.Position)	
	if enemytorso ~= nil then -- if player detected
		isWandering = 1
		local function checkw(t)
			local ci = 3
			if ci > #t then
				ci = 3
			if t[ci] == nil and ci < #t then
					ci = ci + 1
				until t[ci] ~= nil
				return, 0, 0) + t[ci]
				ci = 3
				return t[ci]
		path = pfs:FindPathAsync(hroot.Position, enemytorso.Position)
		waypoint = path:GetWaypoints()
		oldpoints = waypoint
		local connection;
		local direct = Vector3.FromNormalId(Enum.NormalId.Front)
		local ncf = hroot.CFrame *
		direct = ncf.p.unit
		local rootr =, direct)
		local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
		if path and waypoint or checkw(waypoint) then
			if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
				human:MoveTo( checkw(waypoint).Position )
				human.Jump = false
			--[[if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
				human.Jump = true
				connection = human.Changed:connect(function()
					human.Jump = true
				human:MoveTo( checkw(waypoint).Position )
				human.Jump = false
				local bodypartnames = GetPlayersBodyParts(enemytorso)
				if p:IsA'Part' and not p.Name == bodypartnames and phit and phit.Name ~= bodypartnames and phit:IsA'Part' and rootr:Distance(phit.Position) < 5 then
					connection = human.Changed:connect(function()
						human.Jump = true
					human.Jump = false
			if connection then
			for i = 3, #oldpoints do
				human:MoveTo( oldpoints[i].Position )	
	elseif enemytorso == nil and canWander then -- if player not detected
		isWandering = 0
		path = nil
		waypoint = nil

Look how complicated it is!

From the two scripts above, I think you should be able to get a general idea of what I am trying to ask:

How did these scripters manage to find the best and efficient yet advance solution of these problems?

1 Like



There is no best way to make a script you can make them from a lot of different approach and it still functioning the same and the bot one was certainly over complicated thing and use some outdated properties

Now to answer your question if you know how math (in this example sine and cos) work and know how each function , methods and properties work (especially the one that can only be access with script and not in properties explorer) then you will know what to do with these knowledge when the time come

Basically it all come down to experience and how much you familiar with script in general


Referencing online resources, and breaking down the code into little tasks that are ez to handle.


Like making anything, core concepts of an idea are made, then improved, then added together with another component to achieve the desired goal. If you were to look at a car, it’s very mechanically complex, but broken down it turns into a Chassy, then engine, then cylinder, and what’s left is just a cylinder head and some fuel. Easier to understand than the entire car. Take the time to inspect how every piece works and rebuild the concept step by step, hopefully understanding why it was designed the way it was and why the pieces work together.


Your reply to my question is pretty scarce and vague. Please provide more context.

@RandomPlayerOne1 @Rabbit_Lord @santafatso28
Thanks for the reply. I agree that breaking a complex substance into smaller digestible pieces can certainly be a guide to create something advance. How long have you been scripting? What creations have you created throughout your scripting journey? I would like to understand more of your perspective of your answer.

1 Like

I don’t have any completed project myself for a lot of reason but i do have a lot of small creation

Here is some small thing I done

for my perspective I always draw result on how I will script some feature in my head first and how can I connect them together then I choose what I need to use

Let’s say i wanted to make fireball that do curve motion to certain location

(For Curve motion I would look for Bézier Curves) [Choosing Library/Function Part]

(Will this fireball have hitbox or just travel to goal location then what happen next after the fireball hit target or finished traveling will it have distance limit? will it have cooldown, Damage, Fire Damage? ) [Designing Feature Part]

Then after design the thing you want to create now time to do it

(Find extra library/thing you will use that you thought was missing after design how will it work) [Choosing Library/Function Part 2] (Don’t stress much on this one if you have no idea what is missing you will eventually know what you are missing when start coding)

After coding and Debugging and work as intended

(Can I somehow improve this code further? can I cached this fireball for later cast? would it still be working as intended if i reduce it’s accuracy in favor of performance?) [Optimization Part]

(Do I like it?) [Self Feedback Part]
(If yes then congratulation if no then what part you don’t like? not enough curve? too choppy? not enough visual? then adjust it as you see fit)

these thing always go in my head whenever I scripting something and I am sure other developer have different perspective than me

I am not sure if what I just said will make sense to you but feel free to ask I will answer if I can

and lastly don’t let’s these huge text and a lot of small step overwhelm you it will be really fun when you actually start coding and learn them


Well we find solutions by looking into what we are creating and try to find the best way to make it work. Knowing some math and algorithms can give us a headstart because some of the algorithms we may use are widely used and can sometimes even be found in nature, so by knowing some of these, how they could link, we already know some of the things we need to do, The first one is very well made but can vary depending on fps and such, I am not a fan of the second code because it uses bad variable name, repetition, using a function more time than it needs, and deprecated functions.
other than those it is just using pathfinding in a way that really isnt necessary.


Its just like math, you formulate the idea but in more efficient ways.

The more you know the more efficient you will be.
But as newton said…
for every action (force) in nature there is an equal and opposite reaction
their will always be equivalent exchange. so everything will depend on your decision [and/or everyone].

Roblox is made with C++, it is a multibillion-dollar company. These scripts are made by Roblox, and if they can create a platform like Roblox with C++ they can certainly create some scripts with Lua, as it is one of the easiest scripting languages.

And they pretty much made their own programming language “Luau!”

Then again as lots of people have mentioned and will continue saying: It takes practice.

Hell, I’ve been scripting in Luau for 3 years and still find out new things every now and then! It took me countless nights and debugging to fix my bugs and mistakes. I later learned to find them myself as for a long time I didn’t have access to the forums. Now I can pretty much learn anything I want just by looking at the documentation :slight_smile:

One of the most important skills that people miss is learning to LEARN by yourself.


Necrobumping here, but there is one best way to make a script. While this goal may be unattainable, the goal in all programming is to get as close to the perfect solution as possible. It is just harder to find the solution the more complex the goal is.

For example the best way to print 1+1 is objectively print(1+1).

I see I am not professional on script or anything I guess I still have a lot to learn

You are fine and you could argue against this. You could say this is a more pythonic belief and one that isn’t agreed upon.

1 Like