Help needed switching to camera part in my plane system

Hey there! I’m making a game where you can fly planes, and the planes has a camera part made of a brick. But I don’t know how to make your view switch to that camera when you sit in the plane. Can someone help me figure it out?

2 Likes

local script :

local camera = game.Workspace.CurrentCamera
local part = game.Workspace:WaitForChild("Part") -- Change to where u want to see.

if part and camera ~= nil then
   camera.CameraType = Enum.CameraType.Scriptable -- Change the camera behaviour
   camera.CFrame = part.CFrame -- Set the Camera.CFrame to part.CFrame
end

You probably could use a gui to switch between perspective.
Just a very basic local script.

I’ve tried it, but I don’t really know how to detect if the player is in the vehicleseat or not.

1 Like

Seats (and by extension, VehicleSeats) have an Occupant property that reference the Humanoid that’s currently sitting on that seat.

1 Like

Baseplate.rbxl (44.6 KB)

I made a camera that set to part cframe when Character is sitting. When character isn’t sitting, the camera is set back to character.Head.

local script in StarterCharacterScript :

local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local part = game.Workspace:WaitForChild("Part")
local camera = game.Workspace.CurrentCamera

local current = true

local tweenS = game:GetService("TweenService")
local newI = TweenInfo.new(3, Enum.EasingStyle.Quart)

remote.OnClientEvent:Connect(function(debounce)
	if current == debounce then
		debounce = false
		
		camera.CameraType = Enum.CameraType.Scriptable
		
		local n = tweenS:Create(camera, newI, {CFrame = part.CFrame})
		n:Play()
	elseif current ~= debounce then
		debounce = true
		
		local g = tweenS:Create(camera, newI, {CFrame = script.Parent:WaitForChild("Head").CFrame})
		g:Play()
		
		if g.Completed then
			camera.CameraType = Enum.CameraType.Custom
		end	
	end
end)

Script inside part :

local seat = script.Parent
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

seat.ChildAdded:Connect(function(child)
	print(child.Part1) -- HumanoidRootPart
	
	local character = child.Part1.Parent
	if character ~= nil then
		remote:FireClient(game.Players:FindFirstChild(character.Name), true)
	end
end)

seat.ChildRemoved:Connect(function(child)
	print(child.Part1) -- HumanoidRootPart

	local character = child.Part1.Parent
	if character ~= nil then
		remote:FireClient(game.Players:FindFirstChild(character.Name), false)
	end
end)

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