Hi devs,
I made a camera effect for a menu, but I was wondering if I could optimize it, I mean look at this and tell me if I should store the tween and stop it then create another play it and you know or just let the code as it is actually or any suggestions would be appreciated :
local ts = game:GetService("TweenService")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local char = workspace:WaitForChild(plr.Name)
local hrp = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local init = CFrame.new(hrp.Position - Vector3.new(0, 0, 10)) * CFrame.Angles(0, math.rad(180), 0)
local info = TweenInfo.new(1)
local force = 10
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = init
mouse.Move:Connect(function()
local center = cam.ViewportSize / 2
local x = ((center.Y - mouse.Y) / center.Y) * force
local y = ((center.X - mouse.X) / center.X) * force
local tween = ts:Create(cam, info, {["CFrame"] = init * CFrame.Angles(math.rad(x), math.rad(y), 0)})
tween:Play()
end)
Thanks u very much for ur help and ur time and have a nice day !