Camera is bugged

I’m still not great at scripting in ROBLOX but I’m trying, basically, I’ve made a menu with an intro and a parallax effect. I’ve created a script to change the camera back to the player and make a sort of fade in and out. When the button is pressed, it goes back to the player camera correctly but I can only control the camera using the arrow keys and not by using the mouse. I’m unsure if this is because of studio or my script.

Video

Watch broken i think | Streamable

Script

**Button Handler **

local PlayBtn = script.Parent.PlayBtn
local CreditsBtn = script.Parent.CreditsBtn
local RolesBtn = script.Parent.RolesBtn
local SettingsBtn = script.Parent.SettingsBtn
local blackScreen = game.StarterGui.ScreenEffects.Frame.BlackScreen

local mainmenu = script.Parent

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

-- Play Button
local offScreenPos = UDim2.new(0.333, 0, 0.972, 0)

PlayBtn.Activated:Connect(function()
	local playTween = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	local tweenPlay = TweenService:Create(mainmenu, playTween, {Position = offScreenPos})
	tweenPlay:Play()

	local fadeInTween = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	local fadeIn = TweenService:Create(blackScreen, fadeInTween, {BackgroundTransparency = 0})
	fadeIn:Play()
	fadeIn.Completed:Wait()

	local player = Players.LocalPlayer
	local camera = workspace.CurrentCamera

	if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		camera.CameraType = Enum.CameraType.Custom
		camera.CFrame = player.Character.HumanoidRootPart.CFrame
	else
		warn("Player or HumanoidRootPart not found!")
	end

	local fadeOutTween = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	local fadeOut = TweenService:Create(blackScreen, fadeOutTween, {BackgroundTransparency = 1})
	fadeOut:Play()
end)

There is a second script handling the cameras for the intro part, I’ll put a snippet of what I think might be important

local camera = workspace.CurrentCamera -- Ensure you're referencing the current camera
local camera1 = workspace.MenuArea:FindFirstChild("MouseCam")

local mainmenu = game.Players.LocalPlayer.PlayerGui.MenuGui.Frame.ButtonHolder
local targetPosition = UDim2.new(0.333, 0, 0.656, 0) -- On-screen position

if camera1 then
	camera.CameraType = Enum.CameraType.Scriptable -- Allow manual control
	camera.CFrame = camera1.CFrame

	local mouse = game.Players.LocalPlayer:GetMouse()

	-- Update camera based on mouse movement
	mouse.Move:Connect(function()
		-- Calculate parallax effect offset
		local offsetX = mouse.X / workspace.CurrentCamera.ViewportSize.X -- Normalize X movement
		local offsetY = mouse.Y / workspace.CurrentCamera.ViewportSize.Y -- Normalize Y movement

		local parallaxStrength = 1 -- Adjust strength of parallax effect (tweak as needed)

		-- Apply offset relative to original camera position
		local newCFrame = camera1.CFrame:ToWorldSpace(
			CFrame.new(offsetX * parallaxStrength, offsetY * parallaxStrength, 0)
		)

		camera.CFrame = newCFrame
	end)

	-- Tween mainmenu to the target position
	local TweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) -- Adjust time and style as needed
	local tween = TweenService:Create(mainmenu, tweenInfo, {Position = targetPosition})
	tween:Play()

Any help is appreciated, thanks!

1 Like

Could you print offsetX and offsetY?

EDIT:
Isn’t mouse.X and mouse.Y in the middle so any changes need to be calculated from the midpoint?

local screenSize = workspace.CurrentCamera.ViewportSize
local offsetX = (mouse.X - screenSize.X/2) / screenSize.X
local offsetY = (mouse.Y - screenSize.Y/2) / screenSize.Y

Won’t it just constant print the value with each mouse movement?

1 Like