Camera Switching Problem

My coding experience is very low so please explain with detail if possible!

So, I look up a tutorial on how to move the camera where ever your mouse is (which works) and I have a tiny problem because I’m trying to switch up the cameras to one of my parts. (I have parts as cameras)

Camera Parts:

Screenshot 2024-02-21 145556

Code:

local soundservice = game:GetService("SoundService")
local tweenservice = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local menucamera = workspace.CameraScenes.MenuCamera
local shopcamera = workspace.CameraScenes.ShopCamera
local certaincamera = workspace.CurrentCamera
certaincamera.CameraType = Enum.CameraType.Scriptable
local MOVE_SPEED = 150


local function UpdateCamera()
	local Center = menucamera.CFrame
	local MoveVector = Vector3.new((Mouse.X - Center.X)/MOVE_SPEED, (Mouse.Y - Center.Y)/MOVE_SPEED, 0)
	certaincamera.CFrame = menucamera.CFrame * CFrame.Angles(math.rad(-(Mouse.Y - Center.Y)/MOVE_SPEED), math.rad(-(Mouse.X - Center.Y)/MOVE_SPEED), 0)
end
local Connection = RunService.RenderStepped:Connect(UpdateCamera)


local fade = script.Parent.Frame.Fade

	
local credittext = script.Parent.Frame.credits.TextLabel
local settingtext = script.Parent.Frame.settings.TextLabel
local playtext = script.Parent.Frame.play.TextLabel
local shoptext = script.Parent.Frame.shop.TextLabel


local credit = script.Parent.Frame.credits
local setting = script.Parent.Frame.settings
local play = script.Parent.Frame.play
local shop = script.Parent.Frame.shop
local title = script.Parent.Frame.TITLENAME



--mouse enter's
play.MouseEnter:Connect(function()
	soundservice.MouseSounds.ButtonHover:Play()
	play.TextColor3 = Color3.fromRGB(255,170,0)
	playtext.Visible = true
end)



play.MouseLeave:Connect(function()
	play.TextColor3 = Color3.fromRGB(255,255,255)
	playtext.Visible = false
end)


play.MouseButton1Up:Connect(function()
	certaincamera.CFrame =  menucamera.CFrame
end)

setting.MouseEnter:Connect(function()
	soundservice.MouseSounds.ButtonHover:Play()
	setting.TextColor3 = Color3.fromRGB(255,170,0) 
	settingtext.Visible = true
end)



setting.MouseLeave:Connect(function()
	setting.TextColor3 = Color3.fromRGB(255,255,255)
	settingtext.Visible = false
end)



shop.MouseEnter:Connect(function()
	soundservice.MouseSounds.ButtonHover:Play()
	shop.TextColor3 = Color3.fromRGB(255,170,0) 
	shoptext.Visible = true
end)


shop.MouseLeave:Connect(function()
	shop.TextColor3 = Color3.fromRGB(255,255,255)
	shoptext.Visible = false
end)



credit.MouseEnter:Connect(function()
	soundservice.MouseSounds.ButtonHover:Play()
	credit.TextColor3 = Color3.fromRGB(255,170,0)
	credittext.Visible = true
end)

credit.MouseLeave:Connect(function()
	credit.TextColor3 = Color3.fromRGB(255,255,255)
	credittext.Visible = false
end)


--mouse click
shop.MouseButton1Click:Connect(function()
	certaincamera.CFrame =  shopcamera.CFrame
end)

I tried switching the CFrame you can see it in “shop.MouseButton1Click:Connect(function()” and “play.MouseButton1Up:Connect(function()”

1 Like

Video not working. Not sure what’s wrong.

2 Likes

Oh, that’s strange, I can see it just fine (im on mobile)

But its just me clicking gui text buttons, just go gjve proof that the camera wasn’t switching it’s CFrame.

1 Like

Add some prints to this, print(‘test’)

2 Likes

My problem is this:

local certaincamera = workspace.CurrentCamera
certaincamera.CameraType = Enum.CameraType.Scriptable
local MOVE_SPEED = 150


local function UpdateCamera()
	local Center = menucamera.CFrame
	local MoveVector = Vector3.new((Mouse.X - Center.X)/MOVE_SPEED, (Mouse.Y - Center.Y)/MOVE_SPEED, 0)
	certaincamera.CFrame = menucamera.CFrame * CFrame.Angles(math.rad(-(Mouse.Y - Center.Y)/MOVE_SPEED), math.rad(-(Mouse.X - Center.Y)/MOVE_SPEED), 0)
end
local Connection = RunService.RenderStepped:Connect(UpdateCamera)

And i want it to switch CFrame with one of my cameras:

shop.MouseButton1Click:Connect(function()
	certaincamera.CFrame =  shopcamera.CFrame
end)```
1 Like

Oh, yea this definitely wouldn’t work, because you are setting the camera every frame in that loop. When you then press LMB, it just sets it back 1 frame later when the loop runs again

2 Likes

How would i fix it?

I didn’t want a loop (i watched a youtube video btw)

1 Like

It’s not a loop, sorry. It’s an event. Which runs every frame.

UpdateCamera, is it important?

2 Likes

That’s the name of the function.

But I’m trying to see how i can make the camera move slightly to the mouse like for main menus y’know?

1 Like

Oh, right. Well, you should use some form of linear interpolation. Then you can have a goalPosition, and a renderstepped event which always moves it towards the goal.

2 Likes

Sounds difficult, but I’ll try. Thanks!

1 Like

That should do it.

2 Likes