Issue with Switching Camera Types

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? A Smooth Transition on from the Menu to Game.

  2. What is the issue? I designed my code in order to create a fade while the client switches the camera type to Default from Scriptable. So when the fade is done, the camera isn’t on the menu/part I set it to but rather on the character/ the roblox Default Camera System. However, as seen in the video, this doesn not happen like I expected it to, the camera switches to default only after the fade is done Every Time. I will attatch snippets of my code.

P.S If theres a better way to write my code please do mention it in the Comments, I would appreciatte it more and would contribute to enhancing my knowledge. Sorry if my english is difficult to comprehend.

  1. What solutions have you tried so far? I tried making the “Switch” before the fadegui gets Tweened to be transparent. Placed the “Switching line/code” in different places and just could’nt solve it so I went here.
-- MAIN MENU SCRIPT
-- Services
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

-- Modules
local GraphicsModule = require(ReplicatedStorage:WaitForChild("GraphicsModule"))

-- Local Player and GUI
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

-- Camera and Mouse
local camera = Workspace.CurrentCamera
local menuCamera = Workspace:WaitForChild("MenuCam")
local mouse = player:GetMouse()

-- UI Elements
local playButton = script.Parent:WaitForChild("Play")

-- Menu Setup
if not script.Parent.Enabled then
	script.Parent.Enabled = true
end

repeat
	task.wait()
until script.Parent.Enabled

-- Set Camera Type to Scriptable
repeat
	wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

-- Play Sound
local menuSound = script.m1:Play()

-- Move Camera with Mouse
local maxTilt = 10
RunService.RenderStepped:Connect(function()
	camera.CFrame = menuCamera.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end)

-- UI Fade Function
local function Fade(holdTime, fadeTime)
	playButton.Visible = false

	local mask = Instance.new("Frame")
	mask.Size = UDim2.new(1, 0, 1, 0)
	mask.Position = UDim2.new(0, 0, 0)
	mask.BackgroundColor3 = Color3.new(0, 0, 0)
	mask.Parent = playerGui:WaitForChild("Temp")
	mask.Transparency = 1

	local fadeInInfo = TweenInfo.new(fadeTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	local fadeIn = TweenService:Create(mask, fadeInInfo, { Transparency = 0 })

	local fadeOutInfo = TweenInfo.new(fadeTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	local fadeOut = TweenService:Create(mask, fadeOutInfo, { Transparency = 1 })

	fadeIn:Play()
	task.wait(holdTime)

	repeat
		task.wait()
		camera.CameraType = Enum.CameraType.Custom
	until camera.CameraType == Enum.CameraType.Custom

	ReplicatedStorage.GeneralRE:FireServer(player)
	fadeOut:Play()

	task.wait(fadeTime)

	script.Parent.Parent.GuideHandler.Enabled = true
	script.Parent.Parent:WaitForChild("VHS").Enabled = true
	mask:Destroy()
end

-- Function to Remove Menu
local function RemoveMenu()
	GraphicsModule.Fade(3, 0.75)
	ReplicatedStorage.Ready:FireServer(player)
end

-- Function to Handle Button Interactions
local function Interact(mode)
	if mode == "HOVER" then
		SoundService.sfx.Hover:Play()
		playButton.Text = ">>Play"
	elseif mode == "CLICK" then
		SoundService.sfx.Click:Play()
	elseif mode == "LEAVE" then
		playButton.Text = "Play"
	end
end

-- Connect Button Click Events
playButton.MouseButton1Click:Connect(function()
	Interact("CLICK")
	RemoveMenu()
	script.Parent:Destroy()
end)

playButton.MouseEnter:Connect(function()
	Interact("HOVER")
end)

playButton.MouseLeave:Connect(function()
	Interact("LEAVE")
end)
local TS = game:GetService("TweenService")

local GraphicsModule = {}
local Player = game:GetService("Players")

local plr = Player.LocalPlayer
local plrGui = plr.PlayerGui
local cam = game.Workspace.CurrentCamera

function GraphicsModule.Fade(holdTime, fadeTime)
	local Mask = Instance.new("Frame")
	Mask.Size = UDim2.new(1, 0, 1, 0)
	Mask.Position = UDim2.new(0,0,0)
	Mask.BackgroundColor3 = Color3.new(0, 0, 0)
	Mask.Position = UDim2.new(0, 0, 0)
	Mask.Parent = plrGui:WaitForChild("Temp")
	Mask.Transparency = 1

	local FadeinInfo = TweenInfo.new(fadeTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	local FadeIn = TS:Create(Mask, FadeinInfo, { Transparency = 0 })


	local FadeoutInfo = TweenInfo.new(fadeTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
	local FadeOut = TS:Create(Mask, FadeoutInfo, { Transparency = 1 })
	
	FadeIn:Play()
	task.wait(holdTime)
	FadeOut:Play()
	
	task.wait(fadeTime)
	repeat
		task.wait()
		cam.CameraType = Enum.CameraType.Custom
	until cam.CameraType == Enum.CameraType.Custom
	Mask:Destroy()
end

function GraphicsModule.Blackout(holdTime:number?)

	local fadeout = false

	local Mask = Instance.new("Frame")
	Mask.Size = UDim2.new(1, 0, 1, 0)
	Mask.BackgroundColor3 = Color3.new(0, 0, 0)
	Mask.Position = UDim2.new(0,0,0)
	Mask.Parent = plr.PlayerGui:WaitForChild("Temp")
	Mask.Transparency = 0
	task.wait(holdTime)
	fadeout = true
	task.wait()
	while fadeout == true do
		if Mask.Transparency >= 1 then
			Mask:Destroy()
			fadeout = false
			break
		end
		Mask.Transparency += 0.05
		task.wait(.01)
	end
end

return GraphicsModule

Video Link: Upload files for free - bandicam 2024-02-07 05-54-37-313.mp4 - ufile.io

2 Likes

I forgot to write that, The code block below the Main Menu Script is the “Graphics Module” which is the one used on the main script :slight_smile:

1 Like

Did you mean to provide a video because I don’t see it.

1 Like