Changing Camera Cframe to a Spacific part.Cframe

It doesn’t work and when I am pressing C it is not printing this to the output.
Screenshot_59

if processed then
				return
			end

try removing this line

1 Like

here this might help

I removed it, but it still not working.

In the second script the input began function shouldn’t work because User Input Service is client side only.

I see, so if I make a local script like this :

if Seat.Occupant ~= nil  and key.KeyCode == Enum.KeyCode.C then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = part.CFrame

Will it change the camera cframe of only the player who pressed c , or everyone else in the server as well?

You have to run the positioning in RunService, it has to be updated in a loop to position correctly!! Running the function should update the position once, but if you want the client to have the smoothest camera, you’d

RunService.RenderStepped:Connect(function()
    camera.CFrame = part.CFrame
end)
1 Like
if Seat.Occupant == myHumanoid and key.KeyCode == Enum.KeyCode.C then

myHumanoid is the player’s Humanoid
you need to check if the player is the seat’s occupant and not check if the seat’s Occupant is anyone

The Local Script :

local userInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local carSeat = -- the seat

userInputService.InputBegan:Connect(function(input)
	if carSeat.Occupant == myHumanoid and input.KeyCode == Enum.KeyCode.C then

		-- change the camera
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = targetPart.CFrame
	end
end)
1 Like

It did not work. I used the script using this way while using myHumanoid which didn’t work and then humanoid instead of myHumanoid.

local camera = workspace.CurrentCamera
local userInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local carSeat = game.Workspace:WaitForChild("VehicleSeat")
local targetPart = game.Workspace:WaitForChild("sakuracam1")


userInputService.InputBegan:Connect(function(input)
	if carSeat.Occupant == humanoid and input.KeyCode == Enum.KeyCode.C then

		-- change the camera
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = targetPart.CFrame
	end
end)

I will try it on a clean game and let you know.

local Camera = workspace.CurrentCamera
local part = workspace:WaitForChild("sakuracam1")



game.ReplicatedStorage:WaitForChild("CARCAMERA").OnClientEvent:connect(function()

	Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CameraSubject = part
	Camera.CFrame = part.CFrame
	print("camera to cframe")



end)

You just need to set a CameraSubject. :smile:

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
     local occ = seat.Occupant or nil
     if occ then
          camera.CameraType = Enum.CameraType.Scriptable
          RunService.RenderStepped:Connect(function()
		       camera.CFrame = targetPart.CFrame
          end)
     end
end)

Did you put the local script inside StarterCharacterScripts ?

1 Like

I did not. Now it is working. Thank you so much.

You’re welcome

Also, if you want the code similar to the one you’ve made and works try this

add a Remote Event in Replicated Storage and call it SeatOccupied

add a Local Script inside StarterCharacterScripts that contain the following code :

local replicatedStorage = game:GetService("ReplicatedStorage")
local seatOccupied = replicatedStorage:WaitForChild("SeatOccupied")

local userInputService = game:GetService("UserInputService")
local cameraKey = Enum.KeyCode.C -- the key needed to be pressed so the camera can Change

local myCharacter = script.Parent
local myHumanoid = myCharacter:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local occupied
local lastSeat
local targetCFrame

seatOccupied.OnClientEvent:Connect(function(cameraCFrame)
	occupied = true
	lastSeat = myHumanoid.SeatPart
	targetCFrame = cameraCFrame
end)

myHumanoid:GetPropertyChangedSignal("SeatPart"):Connect(function()
	if occupied then
		occupied = false
		camera.CameraType = Enum.CameraType.Custom
	end
end)

userInputService.InputBegan:Connect(function(input)
	if occupied and input.KeyCode == cameraKey then
		
		if camera.CameraType == Enum.CameraType.Scriptable then
			camera.CameraType = Enum.CameraType.Custom	
		else
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CFrame = targetCFrame
		end	
	end
end)

and make a Seat / VehicleSeat and add this script to it :

local replicatedStorage = game:GetService("ReplicatedStorage")
local seatOccupied = replicatedStorage.SeatOccupied

local seat = script.Parent

local players = game:GetService("Players")

local firstPersonCFrame = workspace.Target -- the part that has the CFrame of the camera in first person

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		
		local humanoid = seat.Occupant
		local character = humanoid.Parent
		local player = players:GetPlayerFromCharacter(character)
		
		if player then
			seatOccupied:FireClient(player, firstPersonCFrame.CFrame)
		end
	end
end)

and it should work.

1 Like

Thank you so much, I will try this one now.