Why is this Variable not declared anywhere?

I found this huge crouch and prone script on toolbox consisting of 350 lines
I unfortunately found myself using it cuz of the noob I am and spent waayy too much time on it to go back. Now I noticed that not all lines here contribute to crouching and proning idk why. But this one specific function that I need to offset the camera uses a variable that is not declared anywhere :

function TweenCOffset(CO, t)
	coroutine.resume(coroutine.create(function()
		COn = COn and COn + 1 or 0 local COn_S = COn
		for i = 1, t do
			if COn ~= COn_S then break end
			char.Humanoid.CameraOffset = char.Humanoid.CameraOffset + (CO - char.Humanoid.CameraOffset) * (i / t)
			game:GetService("RunService").RenderStepped:wait()
		end
	end))
end

What is this variable COn? Where is this declared? And why can’t I use this outside of this specific script?

This COn was used 15 times in the entire script and it is declared absolutely nowhere even though I ctrl+f’ed it to absolute hell.

The entire script:

repeat wait() until game.Players.LocalPlayer.Character
repeat wait(1) until game.Players.LocalPlayer.Character:IsDescendantOf(game.Workspace)
wait(4 / 20)

local Player = game.Players.LocalPlayer
local player = game.Players.LocalPlayer
local Character = Player.Character
local char = Player.Character
local Humanoid = Character.Humanoid
local Mouse = Player:GetMouse()
local mouse = Player:GetMouse()

local Camera = game.Workspace.CurrentCamera

local HumanoidRootPart = Character.HumanoidRootPart

local Torso = Character.Torso
local Neck = Torso:WaitForChild("Neck")

game.Players.LocalPlayer.CameraMaxZoomDistance = 15
game.Players.LocalPlayer.CameraMinZoomDistance = 0

local NightVision = false


local AltPressed = false

local Stances = 0
_G.SteadyStance = false
_G.LeanR = 0
_G.LeanL = 0

local RAW
local LAW
----------------
local RootPart = char:WaitForChild("HumanoidRootPart")
local RootJoint = RootPart.RootJoint
RootJoint.C0 = CFrame.new()
RootJoint.C1 = CFrame.new()

local Aiming = false

local ZoomDistance = 40

local NV

----------------

---------------------------------------------------------------------------------------
---------------- [ Tween Module ] --------------------------------------------------------
---------------------------------------------------------------------------------------


--[[
	
	tweenJoint Function Parameters:
	
	Object Joint - This has to be a weld with a C0 and C1 property
	
	CFrame newC0 - This is what the new C0 of the weld will be. You can put nil if you don't want to effect the C0
	
	CFrame newC1 - This is what the new C1 of the weld will be. You can put nil if you don't want to effect the C1
	
	function Alpha - This is an alpha function that takes an input parameter of a number between 0 and 90 and returns a number between 0 and 1.
		For example, function(X) return math.sin(math.rad(X)) end
		
	float Duration - This is how long the tweening takes to complete
	
--]]
 RS = game:GetService("RunService")



function tweenJoint(Joint, newC0, newC1, Alpha, Duration)
	spawn(function()
		local newCode = math.random(-1e9, 1e9) --This creates a random code between -1000000000 and 1000000000
		local tweenIndicator = nil
		if (not Joint:findFirstChild("tweenCode")) then --If the joint isn't being tweened, then
			tweenIndicator = Instance.new("IntValue")
			tweenIndicator.Name = "tweenCode"
			tweenIndicator.Value = newCode
			tweenIndicator.Parent = Joint
		else
			tweenIndicator = Joint.tweenCode
			tweenIndicator.Value = newCode --If the joint is already being tweened, this will change the code, and the tween loop will stop
		end
		if Duration <= 0 then --If the duration is less than or equal to 0 then there's no need for a tweening loop
			if newC0 then Joint.C0 = newC0 end
			if newC1 then Joint.C1 = newC1 end
		else
			local Increment = 1.5 / Duration --Calculate the increment here so it doesn't need to be calculated in the loop
			local startC0 = Joint.C0
			local startC1 = Joint.C1
			local X = 0
			while true do
				RS.RenderStepped:wait() --This makes the for loop step every 1/60th of a second
				local newX = X + Increment
				X = (newX > 90 and 90 or newX) --Makes sure the X never goes above 90
				if tweenIndicator.Value ~= newCode then break end --This makes sure that another tween wasn't called on the same joint
				if newC0 then Joint.C0 = startC0:lerp(newC0, Alpha(X)) end
				if newC1 then Joint.C1 = startC1:lerp(newC1, Alpha(X)) end
				if X == 90 then break end --If the tweening is done...
			end
		end
		if tweenIndicator.Value == newCode then --If this tween functions was the last one called on a joint then it will remove the code
			tweenIndicator:Destroy()
		end
	end)
end

function CreateWeld(Part, CF)
	local w = Instance.new("Weld")
	w.Name = "LegWeld"
	w.Parent = Torso
	w.Part0 = Torso
	w.Part1 = Part

	tweenJoint(w, nil,  CF, function(X) return math.sin(math.rad(X)) end, 0.25)
end

----------------------------------------------
local RS = Torso["Right Shoulder"]
local LS = Torso["Left Shoulder"]
local RH = char["Torso"]:WaitForChild("Right Hip")
local LH = char["Torso"]:WaitForChild("Left Hip")
local LeftLeg = char["Left Leg"]
local RightLeg = char["Right Leg"]
local Proned2



function TweenCOffset(CO, t)
	coroutine.resume(coroutine.create(function()
		COn = COn and COn + 1 or 0 local COn_S = COn
		for i = 1, t do
			if COn ~= COn_S then break end
			char.Humanoid.CameraOffset = char.Humanoid.CameraOffset + (CO - char.Humanoid.CameraOffset) * (i / t)
			game:GetService("RunService").RenderStepped:wait()
		end
	end))
end

function TweenTransparency(Part,Trans, t)
	coroutine.resume(coroutine.create(function()
		COn = COn and COn + 1 or 0 local COn_S = COn
		for i = 1, t do
			if COn ~= COn_S then break end
			Part.Transparency = Part.Transparency + (Trans - Part.Transparency) * (i / t)
			game:GetService("RunService").RenderStepped:wait()
		end
	end))
end

function TweenColor(Part,Color, t)
	coroutine.resume(coroutine.create(function()
		COn = COn and COn + 1 or 0 local COn_S = COn
		for i = 1, t do
			if COn ~= COn_S then break end
			Part.BrickColor = Part.BrickColor + (Color - Part.BrickColor) * (i / t)
			game:GetService("RunService").RenderStepped:wait()
		end
	end))
end

function Stand()

	TweenCOffset(Vector3.new(0,0,0), 20)
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50

	IsStanced = false	

	LH.Part1 = LeftLeg
	RH.Part1 = RightLeg

	Proned2 = Vector3.new(0,0,0)
	tweenJoint(RootJoint, CFrame.new()* CFrame.Angles(math.rad(-0),0,math.rad(0)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RH, CFrame.new(1,-1,0)* CFrame.Angles(math.rad(-0),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LH, CFrame.new(-1,-1,0)* CFrame.Angles(math.rad(-0),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	for i, s in pairs(Torso:GetChildren()) do
		if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
			s:Destroy()
		end
	end
end

function StandEquip()

	TweenCOffset(Vector3.new(0,0,0), 20)
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
	IsStanced = false	

	LH.Part1 = LeftLeg
	RH.Part1 = RightLeg

	Proned2 = Vector3.new(0,0,0)
	tweenJoint(RootJoint, CFrame.new(0,0,0.275)* CFrame.Angles(math.rad(-10),0,math.rad(0)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RH, CFrame.new(1,-1,-0.15)* CFrame.Angles(math.rad(20),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LH, CFrame.new(-1,-1,-0.2)* CFrame.Angles(math.rad(-10),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	for i, s in pairs(Torso:GetChildren()) do
		if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
			s:Destroy()
		end
	end

end



function Crouch()

	TweenCOffset(Vector3.new(0, -1,0), 20)
	Humanoid.WalkSpeed = 8
	Humanoid.JumpPower = 0
	for i, s in pairs(Torso:GetChildren()) do
		if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
			s:Destroy()
		end
	end
	IsStanced = true	
	RH.Part1 = RightLeg
	LH.Part1 = LeftLeg
	Proned2 = Vector3.new(0,0,0)
	tweenJoint(RootJoint, CFrame.new(0,-1,0.25)* CFrame.Angles(math.rad(-10),0,math.rad(0)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RH, CFrame.new(1,-0.35,-0.65)* CFrame.Angles(math.rad(-20),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LH, CFrame.new(-1,-1.25,-0.625)* CFrame.Angles(math.rad(-60),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)

end

function Prone()

	TweenCOffset(Vector3.new(0, -3.25, 0), 20)
	Humanoid.WalkSpeed = 4
	Humanoid.JumpPower = 0 
	IsStanced = true
	RH.Part1 = nil
	LH.Part1 = nil
	Proned2 = Vector3.new(0,0.5,0.5)
	tweenJoint(RootJoint, CFrame.new(0,-2.5,1.35)* CFrame.Angles(math.rad(-90),0,math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(0.9,1.1,0)* CFrame.Angles(math.rad(-180),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-0.9,1.1,0)* CFrame.Angles(math.rad(-180),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)

	CreateWeld(RightLeg, CFrame.new(-0.2,1.85,0)* CFrame.Angles(math.rad(-0),0,math.rad(-20)))
	CreateWeld(LeftLeg, CFrame.new(0.2,1.85,0)* CFrame.Angles(math.rad(-0),0,math.rad(20)))
end

local AlreadyProned = false

mouse.KeyDown:connect(function(Key)
	if Key == "c" and Stances == 0 and not _G.Sprinting and not _G.Lean then
		Stances = 1
		Crouch()

		_G.Crouched = true
	elseif Key == "c" and Stances == 1 and not _G.Sprinting and not _G.Lean   then	
		Stances = 2
		Prone()

		_G.Crouched = false
		_G.Proned = true

	elseif Key == "x" and Stances == 2 and not _G.Sprinting and not _G.Lean   then
		_G.Crouched = true
		_G.Proned = false
		Stances = 1
		Crouch()


	elseif Key == "x" and Stances == 1 and not _G.Sprinting and not _G.Lean   then		
		_G.Crouched = false


		Stances = 0
		if not _G.SteadyStance then
			Stand()
		elseif _G.SteadyStance then
			StandEquip()
		end

	end

	if Key == "z" and not _G.SteadyStance  and Stances == 0 then
		if not _G.Lean and Stances == 0 then
			StandEquip()
		end
		_G.SteadyStance = true
	elseif Key == "z" and _G.SteadyStance  and Stances == 0 then
		if not _G.Lean  and Stances == 0 then
			Stand()

		end
		_G.SteadyStance = false
	end

	if Key:byte() == 308 or Key:byte() == 307 then
		AltPressed = true
		print("Alt pressed")
	end


end)

mouse.KeyUp:connect(function(Key)
	if Key:byte() == 308  then
		AltPressed = false
	end
end)

Stand()

-------------Motor6Ding Section------------------------





--game:GetService("RunService").RenderStepped:connect(function()
--	Mouse.TargetFilter = game.Workspace


--		if Aiming then
--			game:GetService('UserInputService').MouseDeltaSensitivity = Player.PlayerGui:WaitForChild("ScreenGui").Frame.Sensitivity.Text
--		else
--			game:GetService('UserInputService').MouseDeltaSensitivity = 1
--		end

--	Mouse.Button2Down:connect(function()
--		if not Aiming then
--			Aiming = true
--		end
--	end)
--	Mouse.Button2Up:connect(function()
--		if Aiming then
--			Aiming = false
--		end
--	end)	

--end)


It’s because this script is deprecated and outdated, as I can already see the deprecated Roblox Global __G function. This makes variable to be globally used in a script. I think that’s why.

I recommend you NOT to use this function as it’s been deprecated.

1 Like