My camera is not changing it's CFrame

I want to make the camera switch places when the player clicks on a TextButton, starting the game, but instead of switching and removing the camera effects, It removes the camera effects while still keeping the CFrame of the menu camera. I have looked everywhere for solutions, but nothing is helping me.

Here goes my script:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")

local play = script.Parent.Play

repeat wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

local menu = true

if menu then
	camera.CFrame = CFrame.new(workspace.MenuCamera.CFrame.X, workspace.MenuCamera.CFrame.Y, workspace.MenuCamera.CFrame.Z)
	camera.FieldOfView = 70
	local blur = workspace.Blur:Clone()
	blur.Parent = camera
	blur.Enabled = true
elseif not menu then
	camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X - 8, HumanoidRootPart.CFrame.Y + 1, HumanoidRootPart.CFrame.Z + 30)
	camera.FieldOfView = 26	
end

play.MouseButton1Click:Connect(function()
	menu = false
	script.Parent.Visible = false
	camera.Blur:Destroy()
end)

If there is anything I must correct, just tell me.

If Iā€™m correct elseif not menu then is supposed to change the camera cframe after clicking on the text button yes?

In that case you should put the if menu statement inside of a function, and after detecting button click, you call that function while passing the menu value as a parameter.

local function CamChangeFunction(menu)
  if menu then
	camera.CFrame = CFrame.new(workspace.MenuCamera.CFrame.X, workspace.MenuCamera.CFrame.Y, workspace.MenuCamera.CFrame.Z)
	camera.FieldOfView = 70
	local blur = workspace.Blur:Clone()
	blur.Parent = camera
	blur.Enabled = true
  elseif not menu then
	camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X - 8, HumanoidRootPart.CFrame.Y + 1, HumanoidRootPart.CFrame.Z + 30)
	camera.FieldOfView = 26	
  end
end


play.MouseButton1Click:Connect(function()
	menu = false
	script.Parent.Visible = false
	camera.Blur:Destroy()
    CamChangeFunction(menu)  -- Pass the menu variable as a parameter
end)

I have not found any solutions yet, but I think that the if-statement you put in your script would just run one time:

if menu then
    camera.CFrame = CFrame.new(workspace.MenuCamera.CFrame.X, 
    workspace.MenuCamera.CFrame.Y, workspace.MenuCamera.CFrame.Z)
    camera.FieldOfView = 70
    local blur = workspace.Blur:Clone()
    blur.Parent = camera
    blur.Enabled = true
elseif not menu then
    camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X - 8, HumanoidRootPart.CFrame.Y + 1, HumanoidRootPart.CFrame.Z + 30)
    camera.FieldOfView = 26	
end
1 Like

Yes! That worked, Thank you so much!

1 Like