Enum.CameraType.Costum not working?

  1. What do you want to achieve? Keep it simple and clear!
    I want to set the camera back to costum when a button is clicked

  2. What is the issue? Everything works good, the camera rotates how it should, but when the button is clicked, it doesn’t set the camera back

  3. What solutions have you tried so far?

I tried looking at some other code that sets the camera back and tried that, but it didn’t work

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

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

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local target = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local rotationAngle = Instance.new("NumberValue")
local tweenComplete = false

local cameraOffset = Vector3.new(0, 10, 12)
local rotationTime = 15  -- Time in seconds
local rotationDegrees = 360
local rotationRepeatCount = -1  -- Uses -1 so that it won't stop
local lookAtTarget = true  -- Whether the camera tilts to point directly at the target

local function updateCamera()
	if not target then return end
	camera.Focus = target.CFrame
	local rotatedCFrame = CFrame.Angles(0, math.rad(rotationAngle.Value), 0)
	rotatedCFrame = CFrame.new(target.Position) * rotatedCFrame
	camera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))
	if lookAtTarget == true then
		camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
	end
end

-- Set up and start rotation tween
local tweenInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, rotationRepeatCount)
local tween = TweenService:Create(rotationAngle, tweenInfo, {Value=rotationDegrees})
tween.Completed:Connect(function()
	tweenComplete = true
end)
tween:Play()

-- Update camera position while tween runs
RunService.RenderStepped:Connect(function()
	if tweenComplete == false then
		updateCamera()
	end
end)

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
	repeat wait()
		camera.CameraType = Enum.CameraType.Custom
	until camera.CameraType == Enum.CameraType.Custom
end)

The part that doesn’t work is the MouseButton1Click, everything else works, it gets the humanoid, rotates, and tweens all good, I just can’t figure out how to set camera back

Do you want to set the camera back to the player? if so, you can use

camera.CameraSubject = player.Character:WaitForChild("Humanoid")
player.CameraMode = Enum.CameraMode.Classic
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = player.Character:WaitForChild("Head").CFrame

Also, I would refrain from using loops like repeat, especially when dealing with setting the camera to Custom. If you wanted to test if it works, you could use pcall, or print the value of camera.CameraType.
As a side note, wait() should not be used for new work and should be replaced with task.wait()

I want it to be the default camera, the camera that is set when you have no other scripts modifying.

Then the script listed above should work.

I tried and it did not work. I have a theory that maybe the tween just isn’t stopping, it is successfully changing the camera, but the camera keeps tweening. Do you think that is it?

If there is a tween happening when trying to set it back, you should use tween:Stop() or tween:Pause() as tweening would probably interfere with your camera.

I tried tween:Stop() and it didn’t work. I’m just flat out confused now.

Code:

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
	tween:Stop()
	camera.CameraSubject = player.Character:WaitForChild("Humanoid")
	player.CameraMode = Enum.CameraMode.Classic
	camera.CameraType = Enum.CameraType.Custom
	camera.CFrame = player.Character:WaitForChild("Head").CFrame
end)

Hey! I still haven’t figured out how to fix it. I stopped the tween and set the camera. What am I missing!?

Try resetting the character before running the script.

Applying changes on StarterGui will not replicate to the LocalPlayer, since each player has its own PlayerGui which is where you will need to change whatever you want. Also, it’s not a good practice to use a repeat loop for these type of situations, since the player should have previously loaded to be able to click a TextButton there’s no need to use a loop.

local UI = player.PlayerGui:WaitForChild("ScreenGui")

UI:WaitForChild("TextButton").MouseButton1Click:Connect(function()
	camera.CameraType = Enum.CameraType.Custom
end)
1 Like

Where would this script go? Would it be a seperate script?

My code doesn’t work

Here it is (Same code except MouseButton1Click event is changed to what you said)

code:

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

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local target = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local rotationAngle = Instance.new("NumberValue")
local tweenComplete = false

local cameraOffset = Vector3.new(0, 10, 12)
local rotationTime = 30  -- Time in seconds
local rotationDegrees = 360
local rotationRepeatCount = -1  -- Use -1 for infinite repeats
local lookAtTarget = true  -- Whether the camera tilts to point directly at the target

local function updateCamera()
	if not target then return end
	camera.Focus = target.CFrame
	local rotatedCFrame = CFrame.Angles(0, math.rad(rotationAngle.Value), 0)
	rotatedCFrame = CFrame.new(target.Position) * rotatedCFrame
	camera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))
	if lookAtTarget == true then
		camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
	end
end

-- Set up and start rotation tween
local tweenInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, rotationRepeatCount)
local tween = TweenService:Create(rotationAngle, tweenInfo, {Value=rotationDegrees})
tween.Completed:Connect(function()
	tweenComplete = true
end)
tween:Play()

-- Update camera position while tween runs
RunService.RenderStepped:Connect(function()
	if tweenComplete == false then
		updateCamera()
	end
end)

local UI = player.PlayerGui:WaitForChild("ScreenGui")

UI:WaitForChild("TextButton").MouseButton1Click:Connect(function()
	camera.CameraType = Enum.CameraType.Custom
end)

It’s a snippet, you should add it to your own script and implement changes.

By re-reading your code I noticed this event will never fire, since you made the tween infinite. Maybe you’ll want to disconnect the RenderStepped function when the Button gets clicked?

1 Like

Worked like a charm! Tysm, and I’m so sorry this is 12 days late, I forgot, I was sick and didn’t have the time! Thank you so much again, and have a brilliant day!