CurrrentCamera wont change

My code is. This is located in a LocalScript within a textbutton, located in StarterGui

local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraPart = workspace.CameraPart

local function updateCameraCFRAME()
camera.CFrame = cameraPart.CFrame
end

UIS.InputBegan:Wait()
if UIS.KeyboardEnabled then
RS.RenderStepped:Connect(updateCameraCFRAME)
script.Parent.MouseButton1Click:Connect(function()
print("TextButton was MouseButton1Click")
camera.CameraType=Enum.CameraType.Custom
end)
end

Hi!

You have to update the Camera’s CameraType to let the engine know you are manipulating it yourself.

Try something like this as the function;

local function updateCameraCFRAME()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraPart.CFrame
end
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraPart = game.Workspace.CameraPart

local function updateCameraCFRAME()
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = cameraPart.CFrame
    camera.CameraSubject = cameraPart
end

UIS.InputBegan:Wait()

if UIS.KeyboardEnabled then
    RS.RenderStepped:Connect(updateCameraCFRAME)
        script.Parent.MouseButton1Click:Connect(function()
            camera.CameraType = Enum.CameraType.Custom
            camera.CameraSubject = game.Players.LocalPlayer:WaitForChild("Humanoid")
    end)
end

This should work!

I get a stack error on line 18?

I edited the end) because it wasn’t correct btw

Ah, sorry. Did it work though?

No it didnt :frowning:

I get the stack error, which I never understood stack errors. Also, why does it wait for a Humanoid in the first place?

It is just a better practice, can you show me the output?

yeah, it is a print statement (which I added to see if it was the event that wasn’t triggering, which it wasnt)

Check the UserInputService, as the camera stuff is correct.

I think the UserInputStuff is right, as it only happens when its on a keyboard input, which is what I want. It sets the camera, it just won’t set it back to costum when the button is clicked.

it sets the camera after keyboard input, but then when I press the button, nothing happens, when it should set the camera to costum again.

Remove the WaitForChild, and try it then.

Can the camera and/or UserInput be detected (UserInput) or changed (camera) from a LocalScript inside a textbutton?

It still doesn’t work. It does print this time and I get no stack error though.

It should be. Was it not, because both those are client only.

I think you might have misput something in the script.

It’s supposed to be;

camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid

Not;

camera.CameraSubject = game.Players.LocalPlayer

Also; it’s good to check if you have any other scripts that mess with the camera that is potentially messing with this one.