The camera doesn't work when I'm sitting

My goal is when the player is sitting, he is looking from a block but it doesn’t work
The local script put it in Server Storage and StarterPlayerScripts, and it doesn’t work.
Create a local script and write this code. It’s done wrong, help me make it work.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = game.workspace.Camara

char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
	if isSeated and seat.Name == "CameraSeat" then
		
		camPart.CameraType = Enum.CameraType.Custom
		camPart.CFrame = camPart.CFrame
	else
		
	end
end)

  1. Camara isn’t a valid member of workspace, try doing local camPart = workspace.Camera
  2. Try changing the cam.CameraType to Enum.CameraType.Scriptable before changing its properties.

It didn’t wor

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = workspace.Camara

char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
	if isSeated and seat.Name == "CameraSeat" then
		
		camPart.CameraType = Enum.CameraType.Scriptable
		camPart.CFrame = camPart.CFrame
	else
		camPart.CameraType = Enum.CameraType.Custom

	end
end)


Try this:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = Instance.new("Part") -- Create a new Part object to use as the camera seat
camPart.Name = "CameraSeat"
camPart.Anchored = true
camPart.Size = Vector3.new(1, 1, 1) -- Set the size of the seat
camPart.Parent = workspace -- Parent the seat to the workspace

char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
	if isSeated and seat.Name == "CameraSeat" then
		cam.CameraType = Enum.CameraType.Scriptable -- Change the camera type to Scriptable
		cam.CFrame = camPart.CFrame -- Set the camera's CFrame to the seat's CFrame
	else
		cam.CameraType = Enum.CameraType.Custom -- Change the camera type back to Custom when not seated
	end
end)

Make sure to put this local script in StarterPlayerScripts, as it needs to run on the client side. Additionally, make sure to add a part named “CameraSeat” in your game to act as the seat for the player.

If it works but I have difficulty orienting the camera, the camera always points in one direction.

1 Like

So you want it that if the player is not sitting or standing up agian it will go back to the normal camera?

camPart.Position = Vector3.new(49.604, 16.497, -262.572, 0, 280, 0)

The position can be changed but the orientation I don’t know how to do it.

1 Like

To set the orientation (rotation) of the camPart, you can use the CFrame.new() function. Here’s an example of how to set the position and orientation of the camPart:

camPart.CFrame = CFrame.new(Vector3.new(49.604, 16.497, -262.572), Vector3.new(0, 280, 0))

This will set the camPart’s position to Vector3.new(49.604, 16.497, -262.572) and its orientation to Vector3.new(0, 280, 0). Adjust the values accordingly to achieve the desired orientation for your camera seat.

2 Likes
local camPart = workspace.PartA

delete the new instance and use a new block to use as the camera, but the script has an error, when the player dies or restarts, the camera does not activate.
how can you solve it.

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