Problem with Camera Menu

  1. What do you want to achieve? Keep it simple and clear!

Answer: I want to create a system where players can have access back to the camera after they press a specific button.

  1. What is the issue? Include screenshots / videos if possible!

Answer: I don’t know why this system doesn’t work, because every time I click on the specific button, the camera freezes and doesn’t return to the player.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Answer: I’ve looked everywhere possible but haven’t found a solution yet.

Here is the code that I made:

--// Variables

local Camera = workspace.Camera
local cameraPart = game.Workspace:WaitForChild("CameraPart")
local PlayersService = game:GetService("Players")
local Player = PlayersService.LocalPlayer
local Mouse = Player:GetMouse()
local playerGui = Player.PlayerGui
local menuInterfaces = playerGui:WaitForChild("MenuInterfaces")
local HideOutButton = menuInterfaces.HideOut
local RunService = game:GetService("RunService")

--// Number

local maxTilt = 5

--// Boolean

local cameraMenuEnabled = true

--// Function

local function tilt()
	Camera.CameraType = Enum.CameraType.Scriptable
	
	while cameraMenuEnabled do
		Camera.CFrame = cameraPart.CFrame * CFrame.Angles(
			math.rad((((Mouse.Y - Mouse.ViewSizeY / 1) / Mouse.ViewSizeY)) * -maxTilt),
			math.rad((((Mouse.X - Mouse.ViewSizeX / 1) / Mouse.ViewSizeX)) * -maxTilt),
			0)
	if not cameraMenuEnabled then break end
	task.wait()
	end
end
task.spawn(tilt)

--// Button event

HideOutButton.MouseButton1Click:Connect(function()
	cameraMenuEnabled = false
	Camera.CameraType = Enum.CameraType.Custom
end)


Problem

Is’t it just because you are setting the cameraMenuEnabled to false?
Since the tilt script is inside a while camerMenuEnabled = true statement that means that it will only tilt while cameraMenuEnabled = true and you set it to false when the button is pressed.
Try changing this false to a true:
HideOutButton.MouseButton1Click:Connect(function() cameraMenuEnabled = true Camera.CameraType = Enum.CameraType.Custom end)

But I just wanted to set it to false, because if the player presses the Button, he will have access back to the normal camera, as before the player’s camera was in the menu. And i tried the code that you send, but the result is the same as before.

Oh sorry I didn’t understand it properly, it could be because you aren’t specifying what player changes the camera type in the button script.

Recomendo você usar RenderStepped em vez desse while e alterar a variável da camera para workspace.CurrentCamera. Pois você usando essa variável da camera, você está pegando apenas a camera do Studio e não da visão do player em si e o uso de RenderStepped é mais preciso que usar este loop. Acredito que assim deve funcionar.

I had already done this but I had the same error as in the video, i dont really know what’s the problem. :confused:

Opa, eu já tinha feito justamente esse metódo quando comecei a fazer a interface do Menu, só que mais uma vez, ele não estava funcionando. Porém acho que eu descobri uma alternativa no Roblox API para resolver isto.

Qual método precisamente você usou? eu fiz dessa maneira e funcionou. Quer dar uma olhada nas alterações que fiz?

EN: Yep, I finally fixed the bug, I won’t need help anymore. But still, thank you for trying to help me

BR: É, eu finalmente concertei o bug, não irei mais precisar de ajuda. Mas mesmo assim obrigado por tentarem me ajudar

BR: Eu basicamente coloquei um “Destroy()” no script e ele funcionou perfeitamente. Não estou utilizando ele incorretamente pois eu criei um outro script que pode criar uma cópia da interface anterior caso o player queira voltar pra tela do menu principal.

EN: I basically put a “Destroy()” in the script and it worked perfectly. I’m not using it incorrectly because I created another script that can create a copy of the previous interface if the player wants to return to the main menu screen.

--// Button event that destroys the Main Menu

HideOutButton.MouseButton1Click:Connect(function()
	Camera.CameraType = Enum.CameraType.Custom
	game.Lighting:WaitForChild("BlurScene").Enabled = false
	script.Parent.Parent:Destroy() -- This will automatically destroy after the Player clicks the Button
end)

Não te garanto que esse é um formato ideal, acredito que lá na frente você terá problemas com seus jogadores em relação a isso, mas enfim. Que bom que conseguiu resolver. Caso tenha interesse no formato que usei, aqui está e boa sorte com seu projeto :facepunch:

--// Variables
local Camera = workspace.CurrentCamera
local cameraPart = game.Workspace:WaitForChild("CameraPart")
local PlayersService = game:GetService("Players")
local Player = PlayersService.LocalPlayer
local Mouse = Player:GetMouse()
local playerGui = Player.PlayerGui
local menuInterfaces = playerGui:WaitForChild("MenuInterfaces")
local HideOutButton = menuInterfaces.HideOut
local RunService = game:GetService("RunService")

--// Number
local maxTilt = 5

--// Boolean
local cameraMenuEnabled = true

--// Function
local function updateCameraTilt()
	if cameraMenuEnabled then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = cameraPart.CFrame * CFrame.Angles(
			math.rad(((Mouse.Y - Mouse.ViewSizeY / 2) / Mouse.ViewSizeY) * -maxTilt),
			math.rad(((Mouse.X - Mouse.ViewSizeX / 2) / Mouse.ViewSizeX) * -maxTilt),
			0
		)
	else
		Camera.CameraType = Enum.CameraType.Custom
	end
end

RunService.RenderStepped:Connect(updateCameraTilt)

--// Button event
HideOutButton.MouseButton1Click:Connect(function()
	cameraMenuEnabled = false
	Camera.CameraType = Enum.CameraType.Custom
end)
2 Likes

Aaaahhh, nossa! :sweat_smile:

Eu ainda estou aprendendo a programar na Engine do Roblox, ai por isso que eu tinha cometido aquela bobagem, mas o seu script é bem mais eficaz que o metódo que eu tinha feito. Mas enfim, valeu demais ai mano pelo seu ajuste! Ajudou demais agora e obrigado pelo apoio, espero que os seus futuros projetos dêem certo também! :handshake:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.