Some of my code

Some code: want to know if its efficient

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
local HttpService = game:GetService("HttpService")
local CurrentCamera = workspace.CurrentCamera

local Antithetical, Dampener = 1, 2.5
local PreviousLookVector = CurrentCamera.CFrame.LookVector
local MinimumBlurEffect, MaximumBlurEffect = 18, 24

local TweenInfoNew = TweenInfo.new(
	.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)

function DegreesTowardsDot(Theta)
	return math.cos(math.rad(Theta))
end

local BlurEffectTable = {}
local BlurEffect = nil

RunService.RenderStepped:Connect(function()
	if not Lighting:FindFirstChildOfClass("BlurEffect") then
		BlurEffect = Instance.new("BlurEffect")
		BlurEffect.Name = BlurEffectTable[#BlurEffectTable - #BlurEffectTable + 1] or HttpService:GenerateGUID()
		BlurEffect.Size = 0
		BlurEffect.Parent = Lighting
		table.insert(BlurEffectTable, BlurEffect.Name)
	end
	if Antithetical % Dampener == 0 and BlurEffect ~= nil then
		local Dot = PreviousLookVector:Dot(CurrentCamera.CFrame.LookVector)
		if Dot >= DegreesTowardsDot(MinimumBlurEffect) then
			TweenService:Create(BlurEffect, TweenInfoNew, {Size = 0}):Play()
		elseif Dot < DegreesTowardsDot(MinimumBlurEffect) then
			local Equation = (1 - Dot) * MaximumBlurEffect
			TweenService:Create(BlurEffect, TweenInfoNew, {Size = Equation}):Play()
		end
	end
	PreviousLookVector = CurrentCamera.CFrame.LookVector
	Antithetical += 1
end)

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalPlayerHumanoid = LocalPlayerCharacter:WaitForChild("Humanoid")

local NormalFieldOfView, SprintFieldOfView = 70, 82.5
local NormalWalkSpeed, SprintWalkSpeed = 16, LocalPlayerHumanoid.WalkSpeed * 1.5

local LocalPlayerSprinting = false

UserInputService.InputBegan:Connect(function(InputBegan)
	if InputBegan.KeyCode == Enum.KeyCode.LeftShift then
		TweenService:Create(CurrentCamera, TweenInfoNew, {FieldOfView = SprintFieldOfView}):Play()
		TweenService:Create(LocalPlayerHumanoid, TweenInfoNew, {WalkSpeed = SprintWalkSpeed}):Play()
		LocalPlayerSprinting = true
	end
end)

UserInputService.InputEnded:Connect(function(InputEnded)
	if InputEnded.KeyCode == Enum.KeyCode.LeftShift then
		TweenService:Create(CurrentCamera, TweenInfoNew, {FieldOfView = NormalFieldOfView}):Play()
		TweenService:Create(LocalPlayerHumanoid, TweenInfoNew, {WalkSpeed = NormalWalkSpeed}):Play()
		LocalPlayerSprinting = false
	end
end)
```
1 Like

Please do not dump code into the Code Review category without any context. Refer to the category guidelines to understand how best to use this category.

updated for what i want efficient

This still isn’t enough context. It’s too vague to get an understanding of what you’re looking to improve here. In terms of efficiency, where are your benchmarks or slow points? Again, I’m asking you please to read the category guidelines to understand how to post threads here. It should include:

  • A title informing readers beforehand what this code is about.
  • An explanation about what the code is supposed to do.
  • A specific part of your code that you are looking for a review on, not the whole thing.
  • A small blurb regarding the specific selection you made that you’re unhappy with.
  • Some things you’ve considered trying to improve the specific selection.
  • If there are any ways specifically that you want to improve the specific selection.