can you optimize this for me
local main = script.Parent.Frame
local replicatedStorage = game:GetService("ReplicatedStorage")
local displayCPS = main.Click.CPS
local tapEvent = replicatedStorage:WaitForChild("Tap")
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local Icon = script:WaitForChild("Icon")
local mouse = player:GetMouse()
local RunService = game:GetService("RunService")
local clickSplash = false
local extraText = false
local information = require(replicatedStorage:WaitForChild("TappingGameModule"))

_G.makeSound = function(id, v, p)

	local sound = Instance.new("Sound",(p or workspace))
	sound.SoundId = "rbxassetid://"..id
	sound.Volume = v or 1
	return sound
end

local Sounds = {
	Tap = _G.makeSound(177266782, .5),
	Super = _G.makeSound(9060788686, .5),
	Critical = _G.makeSound(9073925913, .5),

}


function updAuto()
	local auto = player:GetAttribute("Auto")
	main.Auto.Decoration.Icon.ImageColor3 = auto and Color3.new(0,1,0) or Color3.new(1,0,0)
end

player:GetAttributeChangedSignal("Auto"):Connect(updAuto)
updAuto()

main.Auto.Button.Activated:Connect(function()
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 843377950) then
		tapEvent:InvokeServer("auto")
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 843377950)
	end
end)

local gainText = script:WaitForChild("Gain")

function click_splash(crit, color, super, taps)
	
	local m = (crit and 1.5 or 1)
	
	local new = gainText:Clone()

	if super then
		new.Size = UDim2.fromScale(new.Size.X.Scale*2, new.Size.Y.Scale*2)
		new.Amount.TextColor3 = Color3.new(0.333333, 0.666667, 1)
		new.ZIndex += 0
	else
		new.Amount.Position = UDim2.fromScale(-.5+math.random(), -1+math.random()*2)
	end
	
	if crit then
		new.Amount.TextColor3 = Color3.new(1,0,0)
		new.Size = UDim2.fromScale(new.Size.X.Scale, new.Size.Y.Scale)
		new.ZIndex += 0
		new.Position = UDim2.fromOffset(mouse.X, mouse.Y)
		new.Parent = script.Parent.Parent
		new.Amount.Text = "CRITICAL"

		task.spawn(function()
			for i=1, 30, 6 do
				task.wait()
				new.Amount.Rotation -= 1
			end
			for i=1, 2 do

				for i=1, 60, 6 do
					task.wait()
					new.Amount.Rotation += 1
				end
				for i=1, 60, 6 do
					task.wait()
					new.Amount.Rotation -= 1
				end
			end
			new:Destroy()
		end)
		
	elseif extraText or super then

		new.Position = UDim2.fromOffset(mouse.X, mouse.Y)
		new.Parent = script.Parent.Parent
		new.Amount.Text = super and "SUPER" or "+".._G.AbrevNum(taps)
		TS:Create(new, TweenInfo.new(.3), {Size = UDim2.fromScale(new.Size.X.Scale*1.2, new.Size.Y.Scale*1.2)}):Play()
		task.delay(.3, function()
			new:Destroy()
		end)
	end
	
	if not clickSplash  then return end

	for i =1, (crit and math.random(7,10) or math.random(3,6))+(super and 8 or 0) do
		local new = Icon:Clone()
		new.ImageColor3 = color or new.ImageColor3
		new.Size = UDim2.fromScale(.034* m,.059* m)
		new.ZIndex = 1
		new.Position = UDim2.fromOffset(mouse.X, mouse.Y)
		new.Parent = script.Parent.Parent
		new.Visible = true
		local Velocity = {math.random(-6,6) * m,-math.random(5,10)* m}
		if super then
			Velocity = {math.random(-8,8) * m*3,math.random(-8,8) * m*3}
		end
		task.spawn(function()
			for i=1, 35 do
				task.wait()
				Velocity[1] = Velocity[1]  * (super and 1.01 or .99)
				Velocity[2] += super and 0 or 1
				new.Position = UDim2.fromOffset(new.Position.X.Offset+Velocity[1], new.Position.Y.Offset+Velocity[2])
			end
			new:Destroy()
		end)
	end
end

local pos = main.Click.Decoration.Icon.Position
local Clicks = 0

-- Function to center UI element
local function centerIcon()
	-- Get screen dimensions
	local screenWidth, screenHeight = workspace.CurrentCamera.ViewportSize.X, workspace.CurrentCamera.ViewportSize.Y
	-- Center the icon by adjusting its position based on its size
	main.Click.Decoration.Icon.Position = UDim2.new(0.5, -main.Click.Decoration.Icon.Size.X.Offset / 2, 0.5, -main.Click.Decoration.Icon.Size.Y.Offset / 2)
end

function click(clickType, anim)
	local result, crit, taps = tapEvent:InvokeServer(clickType)

	if not result then return end

	click_splash(crit, false, false, taps)

	if crit and Sounds.Critical then
		Sounds.Critical:Play()
		return
	end
	if Sounds.Tap then
		Sounds.Tap:Play()
	end
	Clicks += 1
end

local SuperCD, SuperMulti = information.SuperTapCoolDown, information.SuperTapMulti

function superClick()
	local result, crit, taps = tapEvent:InvokeServer("super")

	if not result then return end
	click_splash(crit, Color3.new(1, 0.33, 1), true, taps)

	if Sounds.Super then
		Sounds.Super:Play()
	end
	main.Super.Time.Visible = false
	main.Super.ProgressBar.Visible = true
	main.Super.ProgressBar.Progress.Size = UDim2.fromScale(0.15, 1)
	TS:Create(main.Super.ProgressBar.Progress, TweenInfo.new(SuperCD), {Size = UDim2.fromScale(1, 1)}):Play()
	task.wait(SuperCD)
	main.Super.Time.Visible = true
	main.Super.ProgressBar.Visible = false
	main.Super.Time.Text = "Super"
end

main.Super.Button.Activated:Connect(superClick)
main.Click.Button.Activated:Connect(click)

for _, Ui in {"Click", "Super", "Auto"} do
	local normSize = main[Ui].Decoration.Icon.Size
	for _, event in {"MouseEnter", "MouseLeave"} do
		main[Ui][event]:Connect(function()
			main[Ui].Decoration.Icon.Size = (event == "MouseLeave") and normSize or UDim2.fromScale(normSize.X.Scale * 1.1, normSize.Y.Scale * 1.1)
		end)
	end
end

UIS.InputBegan:Connect(function(input, gp)
	if gp then return end
	local mouseClick = (input.UserInputType == Enum.UserInputType.MouseButton1)
	if mouseClick or (input.UserInputType == Enum.UserInputType.Touch and not mouseClick) then
		click(true)
	end
end)

local tapValue = player:WaitForChild("leaderstats"):WaitForChild(information.MainCurrency)
task.wait(2)
local CPS = 0
local lastTaps = tapValue.Value
local Fire = main.Click.Decoration.Fire

-- Call the centerIcon function to center the icon at the start
centerIcon()

while task.wait(.1) do
	local CurrentTaps = tapValue.Value
	CPS *= .5
	CPS += (CurrentTaps - lastTaps) * 5
	CPS = math.max(0, CPS)
	displayCPS.Text = "CPS: ".._G.AbrevNum(CPS)
	lastTaps = CurrentTaps
	Clicks = math.max(0, Clicks - .5)
	Fire.Visible = (Clicks > 10)

	-- Call the centerIcon function continuously in case the screen is resized
	centerIcon()
end