Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Camera Manipulation Efficiency?

Asked by 9 years ago

How could this be more efficient? When a player holds the left mouse button and moves it around it glitches the camera.

repeat wait() until game:GetService("Players").LocalPlayer

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Progress = ReplicatedStorage:WaitForChild("Progress")
local MapHolder = workspace:WaitForChild("MapHolder")
local SelectedMap = ReplicatedStorage:WaitForChild("SelectedMap")
local Playing = Player:WaitForChild("Playing")

local CurrentCamera = workspace.CurrentCamera
Angle = 0

function UpdateCamera()
    if Progress.Value == true and Playing.Value == false and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CameraSubject = MapHolder:FindFirstChild(SelectedMap.Value):FindFirstChild("PartCAM")
    elseif Progress.Value == false and Playing.Value == false and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CameraSubject = workspace.Lobby:FindFirstChild("PartCAM")
    elseif Progress.Value == true and Playing.Value == true then
        CurrentCamera.CameraSubject = Character:FindFirstChild("Humanoid")
    end
end
Playing.Changed:connect(UpdateCamera)
Progress.Changed:connect(UpdateCamera)
UpdateCamera()


while wait() do
    if Progress.Value == true and Playing.Value == false and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CoordinateFrame = CFrame.new(MapHolder:FindFirstChild(SelectedMap.Value):FindFirstChild("PartCAM").Position) * CFrame.Angles(0, Angle, 0) * CFrame.new(0, 0, -25)
    elseif Progress.Value == false and Playing.Value == false and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CoordinateFrame = CFrame.new(workspace.Lobby:FindFirstChild("PartCAM").Position) * CFrame.Angles(0, Angle, 0) * CFrame.new(0, 0, -25)
    end
    Angle = Angle + math.rad(1)
end

Answer this question