Changing camera types doesn't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make if the player is going into a vehicle seat, the camera is locking into Attach mode.

  2. What is the issue? Include screenshots / videos if possible!
    When I go into the car, it prints out what I want. But the camera is not changing at all.

local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.Camera
local player = game.Players.LocalPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		Camera.CameraType = "Attach"
		print("joined seat")
	else
		Camera.CameraType = "Custom"
		warn("left seat")
	end
end)

Screenshot_82

local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		CurrentCamera.CameraType = Enum.CameraType.Attach
		print("joined seat")
	else
		CurrentCamera.CameraType = Enum.CameraType.Custom
		warn("left seat")
	end
end)

You need to use current camera also.

For me it does still not work!

1 Like

Are there any errors do it show anything? You also haven’t attached the camera to anything that’s probably why.

Wdym with not attached? And no it does not show any errors.

when your using camera.attached you got to attach it to something like a part

How do i need to do that? Camera.attachedobject or something?

1 Like
game:GetService('RunService').Stepped:Connect(function()

camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30) -- change the numbers

end)

Does it needs to look like this?

local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		game:GetService('RunService').Stepped:Connect(function()
			Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10) -- change the numbers
		end)
		game.Workspace.CurrentCamera.CameraType= "Attach"
		print("joined seat")
	else
		game.Workspace.CurrentCamera.CameraType= "Custom"
		warn("left seat")
	end
end)
1 Like

yes but you need to position the camera behind the player. I suggest using another part instead of humanoid though you would need to rotate the part till the camera goes behind the player

Stil not working, now it its only working when i step out the car.

local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		game.Workspace.CurrentCamera.CameraType= "Attach"
		print("joined seat")
Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10) 
	else
		game.Workspace.CurrentCamera.CameraType= "Custom"
		warn("left seat")
	end
end)

Idk but it isn’t working. I copied that script and put it into a local script in starterplayerscripts.

-- [[ use 'workspace' not 'game.Workspace' since the 'workspace' one is a global variable. ]]

local seat = workspace:WaitForChild("Car"):FindFirstChild("VehicleSeat")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		game:GetService('RunService').Stepped:Connect(function()
			Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10) -- change the numbers
		end)
		workspace.CurrentCamera.CameraType = Enum.CameraType.Attach
		print("joined seat")
	else
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		warn("left seat")
	end
end)

This is a Pseudo Code so I’m not sure that this will work but try it out.

It works only when i step out the car!

local seat = workspace.Car.VehicleSeat
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then 
		Camera.CameraType = Enum.CameraType.Attach
		print("joined seat")
	else
		Camera.CameraType = Enum.CameraType.Custom
		warn("left seat")
	end
end)

If I am to answer directly to the question.

local Seat = game.Workspace.Car:WaitForChild("VehicleSeat")
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    local Humanoid = Seat.Occupant

    if Humanoid then
        Camera.CameraType = Enum.CameraType.Scriptable
        
        game:GetService("RunService").Stepped:Connect(function()
            Camera.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position)
            Camera.CameraSubject = Player.Character.HumanoidRootPart
        end)
    else
       Camera.CameraType = Enum.CameraType.Custom
       Camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
    end
end)

That should work,
Make sure this is a LocalScript!

Thank you, only it needs to follow the car. Any solutions?

workspace.CurrentCamera in a server script creates a reference to the server’s camera, not a player’s camera, you’ll need a RemoteEvent which fires some client (the occupant of the seat) and then you can manipulate their camera locally.

Also “game.Players.LocalPlayer” isn’t defined in server scripts.

The reason this script isn’t working as a local script is because the “Occupant” property shared by “Seat” and “VehicleSeat” instances doesn’t replicate to the server.

Okay so i need to fire a event once a player is in the seat from a serverside script, and i need to detect once a event is fired in a local script?