Locked Camera Script

Hello, I need help, there are 2 buttons on UI and if the first one is clicked the camera is going to the selected place and it is locked, the 2nd button will disable the locked camera. Anybody can help?

No, sorry im just asking how to do it because that’s the last thing to finish my big game!

Wait what is “locking” in this case? Do you want the camera to move to a certain position and prevent it from changing and the 2nd one to bring it back to you?

Yes, when the camera is locked, player can’t move it, when the 2nd button is pressed, the camera is back to normal.

I think you could set the CameraType to Fixed to “lock” it and set it back to Custom when unlocking it if I’m understanding correctly

Yeah but Idk how to script it, sorry. I am basic Scripter.

Are you saying something to for example put your camera in a locked view of something and then set it back to the player?

Yeah. Thaat’s what we are talking about.

As @EmbatTheHybrid mentioned you will need to change the cameratype to scriptable and when you want to set it back to the player set it back to custom. When you set it to scriptable you will want to change the cframe as well to put it in the location you desire.

Ooh my bad, if you have 2 buttons, let’s say you put a LocalScript inside the Frame because you’d want them to work locally for each player, and you can get the Camera’s CFrame & changing the CameraType as well:

--Let's say this button will activate the camera to lock to a certain place
wait()
local LockButton = script.Parent.LockButton
local FreeButton = script.Parent.FreeButton

local Camera = workspace.CurrentCamera

LockButton.MouseButton1Click:Connect(function()
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = workspace.Target.CFrame
end)

This script upon clicking the button, will change the Local Player’s camera upon activation & lock it to a certain CFrame point, now you may wonder…What if I wanna convert it back?

Let’s add some more things onto our code:

--Let's say this button will activate the camera to lock to a certain place
wait()
local LockButton = script.Parent.LockButton
local FreeButton = script.Parent.FreeButton

local Camera = workspace.CurrentCamera

LockButton.MouseButton1Click:Connect(function()
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = workspace.Target.CFrame
end)

FreeButton.MouseButton1Click:Connect(function()
    Camera.CameraType = Enum.CameraType.Custom
end)

The FreeButton upon activation will set the local CameraType to Custom, or the player’s camera

(I believe this can work, but I’m not entirely sure)

2 Likes

Thank you so much! That’s what I was waiting for!

If I was faster I would’ve sent mine first haha, but still, congrats on being the solution post!

Oh don’t worry I spent a few minutes literally deciding if this is the solution or not

1 Like

I swear I definitely did not spend 10 minutes writing these posts Thanks!

Just insert 2 of the squiggly lines ~~ and end them whenever you wanna

Yes I did see your edit don’t worry lol

2 Likes