I want the player’s camera orientation to follow the seat’s orientation when they sit, but this script can’t rotate the view 360 degrees.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local LocalPlayer = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local seatedConnection = nil
local renderConnection = nil
local function onSeated(active, seat)
if active and seat and seat:IsA("Seat") then
-- Start updating camera orientation to match seat
if renderConnection then
renderConnection:Disconnect()
end
renderConnection = RunService.RenderStepped:Connect(function()
if seat and seat.Parent then
-- Get seat's orientation
--camera.CameraType = Enum.CameraType.Scriptable
local seatCFrame = seat.CFrame
-- Keep camera position, but set orientation to seat's orientation
camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(seatCFrame:ToEulerAnglesYXZ()) -- CFrame.new(camera.CFrame.Position) *
end
end)
else
-- Restore default camera behavior
if renderConnection then
renderConnection:Disconnect()
--camera.CameraType = Enum.CameraType.Custom
renderConnection = nil
end
end
end
local function onCharacterAdded(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
if seatedConnection then
seatedConnection:Disconnect()
end
seatedConnection = humanoid.Seated:Connect(onSeated)
end
end
LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
if LocalPlayer.Character then
onCharacterAdded(LocalPlayer.Character)
end