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
You need to use BindToRenderStep to set the CFrame exactly after the camera updates:
local RunService = game:GetService("RunService")
BIND_NAME = "After cam update for sitting players"
local function afterCamera(delta)
-- Put your code to overwrite the camera's update
end
-- To start your code (like making a connection)
RunService:BindToRenderStep(BIND_NAME, Enum.RenderPriority.Camera.Value + 1, afterCamera)
-- To end it (like disconnecting a connection)
RunService:UnbindFromRenderStep(BIND_NAME)
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 RunService = game:GetService("RunService")
local seat = nil
BIND_NAME = "After cam update for sitting players"
local function afterCamera(delta)
if seat and seat:IsDescendantOf(Workspace) 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
local function onSeated(active, newSeat)
if active and newSeat and newSeat:IsA("Seat") then
-- Start updating camera orientation to match seat
RunService:UnbindFromRenderStep(BIND_NAME)
seat = newSeat
RunService:BindToRenderStep(BIND_NAME, Enum.RenderPriority.Camera.Value + 1, afterCamera)
else
-- Restore default camera behavior
RunService:UnbindFromRenderStep(BIND_NAME)
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