I was exploring an open-sourced script when I saw this block of code:
CameraShake.OnClientEvent:Connect(function(Param)
if Param == "Shake" then
for i = 1,115 do
local a = math.random(-5,5)/5
local b = math.random(-5,5)/5
local c = math.random(-5,5)/5
char.Humanoid.CameraOffset = Vector3.new(a,b,c)
wait()
end
char.Humanoid.CameraOffset = Vector3.new(0,0,0)
end
end)
What I’m trying to understand is what is the point of dividing the math.random by 5?
It’s just to allow math.random to give back a decimal number since it can only return whole numbers, unless you give it no arguments, math.random(), which case it gives back a random decimal between 0 and 1
In your case it’s to give a number between -1 and 1 using increments of 0.2, let me give an example
So let’s say math.random(-5,5) gave you -3, it then divides that by 5 to give -0.6, then that pattern is repeated 2 more times for the camera offset.
They probably did it like this because using the returned whole number would cause a huge offset in every direction, they had to limit it somehow
No I don’t mean that, I meant that math.random(-5,5)/5 is repeated 3 times for 3 variables to then be set to the Camera Offset as a Vector3, it only really applies to your code as it is repeated 3 times