Trouble with changing angle of Isometric camera (OOP related)

Hi! So, using this tutorial, i made an Object Oriented Programming Isometric Camera for my game. The problem is that, since my game is isometric, the player’s camera will need to change angles sometimes so the Player can see what’s happening. What i did for this is i made a Folder with Models that contain two Hitboxes, one on the front side and the other on the back side. Once they’re touched by the Player, they should change the Player’s Camera’s angle to their Angle attribute. The problem here is that while the Player touching the Hitboxes is detected, the Camera doesn’t switch angles. I put a picture to better explain it.

Here’s the code:

Client:

--||Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--||Variables
local Classes = ReplicatedStorage:WaitForChild("Classes")
local IsometricCamera = require(Classes.IsometricCamera)
local CameraRotationM = require(Classes.CameraRotation)
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.Camera
local Sectors = workspace:WaitForChild("Sectors")
-------------------------
local IC = IsometricCamera.New(Camera, Character, Root, Humanoid)
IC:ConnectRenderStepped()

for _, Sector in ipairs(Sectors:GetChildren()) do
    for _, CameraRotation in ipairs(Sector.CameraRotations:GetChildren()) do
        local CR = CameraRotationM.New(CameraRotation)
    end
end

IsometricCamera Module/Class:

export type IsometricCamera = {
    _Camera: Camera,
    _Character: Model,
    _Root: BasePart,
    _Humanoid: Humanoid
}

local IsometricCamera : IsometricCamera = {}
IsometricCamera.__index = IsometricCamera

--|Settings
local FOV = 1
local Zoom = .25 -- 100<Zoom<=1000 --Controls how zoomed in the camera is
local Distance = 80 * Zoom
local CamCFrameInfo = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, FOV) 

local CamDistance = Distance    
local Multiply = 0.7075      -- Line up multiple objects in a diagonal (default 0.7075)
local CamHeight = CamDistance * Multiply
local CamAngleOffset = 45  -- Angle offset in degrees for tilting the camera around the Y axis
-- Convert angle offset to radians for camera rotation
local AngleRadians = math.rad(CamAngleOffset)

function IsometricCamera.New(Camera: Camera, Character: Model, Root: BasePart, Humanoid: Humanoid)
    local self = setmetatable({}, IsometricCamera)
    self._Camera = Camera
    self._Character = Character
    self._Root = Root
    self._Humanoid = Humanoid
    return self
end

function IsometricCamera:Run()
    self._Camera.CameraType = Enum.CameraType.Scriptable
    self._Camera.CFrame *= CamCFrameInfo
end

function IsometricCamera:FollowCharacter()
    if self._Character and self._Root then
        -- Calculate the camera's position behind the character
        local XOffset = math.sin(AngleRadians) * CamDistance
        local ZOffset = math.cos(AngleRadians) * CamDistance
        local CamPosition = self._Root.Position + Vector3.new(XOffset, CamHeight, ZOffset)
        -- Set the camera's CFrame to follow the player, looking in a fixed direction
        self._Camera.CFrame = CFrame.new(CamPosition, self._Root.Position)
    end
end

function IsometricCamera:SwitchAngle(Angle: number)
    print("Yay!")
    CamAngleOffset = Angle
end

function IsometricCamera:ConnectRenderStepped()
    game:GetService("RunService").RenderStepped:Connect(function()
        self:Run()
        self:FollowCharacter()
    end)
end

return IsometricCamera

CameraRotation Module/Class:

export type CameraRotation = {
    _Model: Model,
    _IC: IsometricCamera.IsometricCamera
}

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Classes = ReplicatedStorage:WaitForChild("Classes")
local IsometricCamera = require(Classes.IsometricCamera)

local CameraRotation : CameraRotation = {}
CameraRotation.__index = CameraRotation

function CameraRotation.New(Model: Model)
    local self = setmetatable({}, CameraRotation)
    self._Model = Model
    
    self._Model.Front.Touched:Connect(function(Hit: BasePart)
        local Player = Players:GetPlayerFromCharacter(Hit.Parent)
        if Player then
            self:Rotate(self._Model.Front:GetAttribute("Angle"))
        end
    end)
    
    self._Model.Back.Touched:Connect(function(Hit: BasePart)
        local Player = Players:GetPlayerFromCharacter(Hit.Parent)
        if Player then
            self:Rotate(self._Model.Back:GetAttribute("Angle"))
        end
    end)
    
    return self
end

function CameraRotation:Rotate(Angle: number)
    print("Works.")
    IsometricCamera:SwitchAngle(Angle)
end

return CameraRotation

You’re changing camAngleOffset, but that is not used. You’ll need to updateAngleRadians as well because that is the variable that the camera is actually using.

I’m sorry, what? I wrote a whole paragraph describing the issue alongside a picture! And i didn’t hint at where the issue might be caused because i don’t know where it could be since i’m relatively new to OOP.

Thanks, it works! But the Hitboxes are extremely sensitive and flicker between Angles whenever the Player touches them. I tried to add a debounce of 2 seconds but it won’t do anything.

Well, I don’t know where you have the parts, but you should put them in such a way that it is impossible for a player to touch both of them at the same time. The .touched event can be tricky to work with and it’s best to design around making it as easy as possible. You don’t want these zones to be touching or have the ability for a player to be in both because then they will fight for ownership. Strategically placing the camera blocks so that the camera only turns when it needs to is the best approach and should come naturally with plenty of spacing between the new and old one. (they don’t have to fill the whole area, just a trigger is ok so long as you can ensure the player touches it once upon entering that zone).

If you want to do it the other way, you’ll basically have to lock out the angle the camera just was until the player stops getting requests to change to the other angle. Tuning this sounds annoying though.