How would I be able to move the camera when the mouse enters a GUI?

I made 3 parts, Left part, Main Part and Right Part and what I want to make is a GUI corresponding to every part that when enterered with the mouse, the camera changes its CFrame to the part’s CFrame.

I don’t know much about camera manipulation and with a small amount of knowledge I tried to make my idea possible. I made a script for every single part and I started making the Left Part script. Everything works fine but I have a problem.

local button = script.Parent
local deb = false
local Left = game.Workspace.Left
local cam = game.Workspace.CurrentCamera
local ts = game:GetService("TweenService")
local EndCFrame = Left.CFrame
local tsInf = TweenInfo.new(0.6, Enum.EasingStyle.Linear)

local function TurnLeft()
	EndCFrame = cam.CFrame * Left.CFrame
	ts:Create(cam, tsInf, {CFrame = EndCFrame}):Play()
end

button.MouseEnter:Connect(TurnLeft)

The problem is that if my mouse leaves the gui and enters again, then the camera’s CFrame will multiply again.But of course I didn’t make an entire topic for such a small issue. I don’t want only to solve this problem but to find more efficient ways to make this camera system as good as possible. So any help would be appreciated.

2 Likes

The problem is that if my mouse leaves the gui and enters again, then the camera’s CFrame will multiply again.

then check if you already hovered over the button, or set the camera cframe to it’s original cframe when you stop hovering
also organize your variables

local TS = game:GetService("TweenService")
local tInfo = TweenInfo.new(0.6) -- default style is linear

local Button = script.Parent
local Left = workspace:WaitForChild("Left")
local Camera = workspace.CurrentCamera

TargetCFrame = Left.CFrame
Turned = false

local function TurnLeft()
  if Turned then return end
  Turned = true
  TargetCFrame = Camera.CFrame * Left.CFrame
  TS:Create(Camera, tInfo, {["CFrame"] = TargetCFrame}):Play()
end

Button.MouseEnter:Connect(TurnLeft)
2 Likes

Alright so I added this script to every part’s script but this only lets me move the camera’s CFrame once for every part. I want it so you can change to left, main or right at any time, sorry if I didn’t make it clear.

1 Like

it doesn’t work because you never added the other 2 functions for middle and right

1 Like

What do you mean 2 other functions? Like the turnLeft function but for every part?

You Need To Change The Camera Type To Scriptable

I already did that in another script