Basically I have a folder in the Workspace called LoadingSystem, this folder contains the block named CameraBlock.
I would like to make it so that when the player joins the game, their camera is automatically placed and locked on the left face of the block. Meaning they cannot move their camera, but it is almost as if they are staring at an object in first person.
The whole point of this is to then make a ScreenGui which allows the player to return their camera back to their character at the spawn they spawned at by clicking the TextButton provided.
I have tried many methods to do this, and nothing seems to be working. Does anyone have any idea how I can make this work perfectly?
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = part
Camera.CFrame = part.CFrame
Change the cameratype to scriptable to allow the camera to be manipulated
Change the camera subject to your camera part
Change the camera CFrame to encapsulate the part CFrame
As a reminder this will not insert the player camera into the left side of the part specifically, this will have the camera facing the front.
Even if the player camera is somewhere else the player can still move, to fix this you can use the sink function
local ContextActionService = game:GetService("ContextActionService")
local Arguments = {false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D}
ContextActionService:BindActionAtPriority("DisableArrowKeys", function()
return Enum.ContextActionResult.Sink
end, unpack(Arguments))
You can access the player’s camera directly from the workspace if this is a local script.
You then need to set it to scriptable and can move it like any other part by setting its CFrame.
Then connect your button event to resetting the cameraType to follow (or whatever character viewtype you are using).
More info on cameras can be found here
Your code will look something like this.
local cam = workspace.CurrentCamera --If local script
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(Vector3Position, Vector3LookVector) --You will need to define these variables yourself.
--Code to add/enable screenGui
--When clicking the screenGui button
button.clickEvent:Connect(function() --your button and chosen clickevent type
cam.CameraType = Enum.CameraType.Follow
screenGui:Destroy() --or disable, or set all frames Visible = false
)
Their character may have loaded, so even though their view is locked, they can still move the character. If this is an issue, set their walkspeed to 0, then reset once the camera returns.
You could just set the Camera CFrame to the part CFrame
There is also no reason to change the cameratype to follow as the part is set in the workspace.
Instead of setting the walkspeed to 0, it is a better practice to disable the keys with ContextActionService.