---------------------[ TWEEN MODULE ]-------------------------------------------------



function tweenFoV(goal, frames)
 coroutine.resume(coroutine.create(function()
  SFn = SFn and SFn + 1 or 0 
  local SFn_S = SFn
  for i = 1, frames do
   if SFn ~= SFn_S then break end
  		 Camera.FieldOfView = Camera.FieldOfView + (goal - Camera.FieldOfView) * (i / frames)
   game:GetService("RunService").RenderStepped:wait()
  end
 end))
end

function Lerp(n,g,t)
	return n+(g-n)*t
end

local 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
		--local tweenIndicator = createTweenIndicator:InvokeServer(Joint, newCode)
		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
			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)
				if tweenIndicator.Value ~= newCode then break end --This makes sure that another tween wasn't called on the same joint
				if (not Equipped) then break end --This stops the tween if the tool is deselected
				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
			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 LoadClientMods()
	for L_335_forvar1, L_336_forvar2 in pairs(GunMods:GetChildren()) do
		if L_336_forvar2:IsA('LocalScript') then
			local L_337_ = L_336_forvar2:clone()
			L_337_.Parent = ModStorageFolder
			L_337_.Disabled = false
		end
	end
end

function UnloadClientMods()
	for L_335_forvar1, L_336_forvar2 in pairs(ModStorageFolder:GetChildren()) do
		if L_336_forvar2:IsA('LocalScript') then
			L_336_forvar2:Destroy()
		end
	end
end

function CheckForHumanoid(L_225_arg1)
	local L_226_ = false
	local L_227_ = nil
	if L_225_arg1 then
		if (L_225_arg1.Parent:FindFirstChildOfClass("Humanoid") or L_225_arg1.Parent.Parent:FindFirstChildOfClass("Humanoid")) then
			L_226_ = true
			if L_225_arg1.Parent:FindFirstChildOfClass('Humanoid') then
				L_227_ = L_225_arg1.Parent:FindFirstChildOfClass('Humanoid')
			elseif L_225_arg1.Parent.Parent:FindFirstChildOfClass('Humanoid') then
				L_227_ = L_225_arg1.Parent.Parent:FindFirstChildOfClass('Humanoid')
			end
		else
			L_226_ = false
		end	
	end
	return L_226_, L_227_
end

function CreateShell()
	delay(math.random(4,8)/10, function()
		if PastaFX:FindFirstChild('ShellCasing') then
			local Som = PastaFX.ShellCasing:clone()
			Som.Parent = Jogador.PlayerGui
			Som.PlaybackSpeed = math.random(30,50)/40
			Som.PlayOnRemove = true
			Debris:AddItem(Som, 0)
		end
	end)
end

local Tracers = 1
function TracerCalculation()
	local VisibleTracer
	if Settings.RandomTracer then
	if (math.random(1, 100) <= Settings.TracerChance) then	
		VisibleTracer = true
	else
		VisibleTracer = false
	end
	else
		if Tracers >= Settings.TracerEveryXShots then
			VisibleTracer = true
			Tracers = 1
		else
			Tracers = Tracers + 1
		end
	end
	return VisibleTracer
end

function CreateBullet(BSpread)

	local Bullet = Instance.new("Part")
	Bullet.Name = Player.Name.."_Bullet"
	Bullet.CanCollide = false
	Bullet.Transparency = 1
	Bullet.FormFactor = "Custom"
	Bullet.Size = Vector3.new(1,1,1)
	local BulletMass = Bullet:GetMass()
	local Force = Vector3.new(0,BulletMass * (196.2) - (Settings.BDrop) * (196.2), 0)
	local BF = Instance.new("BodyForce")
	BF.force = Force
	BF.Parent = Bullet
	local Origin = ArmaClone.SmokePart.Position
	local Direction = ArmaClone.SmokePart.CFrame.lookVector + (ArmaClone.SmokePart.CFrame.upVector * (((Settings.BDrop*Zeroing.Value/2.8)/Settings.BSpeed))/2)
	local BulletCF = CFrame.new(Origin, Origin + Direction)
	local balaspread = CFrame.Angles(
			RAD(RAND(-BSpread - ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier), BSpread + ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier)) / 20),
			RAD(RAND(-BSpread - ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier), BSpread + ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier)) / 20),
			RAD(RAND(-BSpread - ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier), BSpread + ((SpeedPrecision/Saude.Stances.Mobility.Value)*Settings.WalkMultiplier)) / 20)
		)
	Direction = balaspread * Direction	


	Bullet.Parent = BulletModel
	Bullet.CFrame = BulletCF + Direction
	Bullet.Velocity = Direction * Settings.BSpeed
	local RainbowModeCode = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
		
	local Visivel = TracerCalculation()

if Settings.BulletFlare == true and Visivel then
	local bg = Instance.new("BillboardGui", Bullet)
		bg.Adornee = Bullet
		bg.Enabled = false
		local flashsize = math.random(275, 375)/10
		bg.Size = UDim2.new(flashsize, 0, flashsize, 0)
		bg.LightInfluence = 0
		local flash = Instance.new("ImageLabel", bg)
		flash.BackgroundTransparency = 1
		flash.Size = UDim2.new(1, 0, 1, 0)
		flash.Position = UDim2.new(0, 0, 0, 0)
		flash.Image = "http://www.roblox.com/asset/?id=1047066405"

		if Settings.RainbowMode == true then
			flash.ImageColor3 = RainbowModeCode
		else
			flash.ImageColor3 = Settings.BulletFlareColor
		end
		flash.ImageTransparency = math.random(2, 5)/15
		spawn(function()
				wait(.2)
				if Bullet:FindFirstChild("BillboardGui") ~= nil then
				Bullet.BillboardGui.Enabled = true
				end
		end)
end



	if Settings.Tracer == true and Visivel then			--and Visivel

		local At1 = Instance.new("Attachment")
		--	At1.Name = "At1"
		At1.Position = Vector3.new(0,-1,-8)				--(-10,0,0)
		At1.Parent = Bullet

		local At2 = Instance.new("Attachment")
		--	At2.Name = "At2"
		At2.Position = Vector3.new(0,0,8)				--(10,0,0)	
		At2.Parent = Bullet

		local tracerBeam1 = Instance.new("Beam")
		tracerBeam1.Parent = Bullet
		tracerBeam1.Enabled = true
		tracerBeam1.FaceCamera = true
		tracerBeam1.Color = ColorSequence.new(Settings.TracerColor)
		tracerBeam1.Texture = "http://www.roblox.com/asset/?id=1847258023"
		tracerBeam1.LightEmission = 1
		tracerBeam1.LightInfluence = 0
		tracerBeam1.TextureLength = 1
		tracerBeam1.TextureSpeed = 0
		tracerBeam1.TextureMode = Enum.TextureMode.Stretch
		tracerBeam1.Attachment0 = At2
		tracerBeam1.Attachment1 = At1
		tracerBeam1.Segments = 2
		tracerBeam1.Width0 = 1
		tracerBeam1.Width1 = 3	
		tracerBeam1.CurveSize0 = 0
		tracerBeam1.CurveSize1 = 0	
		tracerBeam1.Transparency = NumberSequence.new(0)
		local tracerBeam2 = tracerBeam1:Clone()	
		tracerBeam2.Parent = Bullet

		--	print("tracer ran")	
