Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Vehicle Camera Focuses On Part?

How would I get it so when a player is in a Vehicle seat, the players camera will focus on a part called Focus in the Vehicle instead of on the Vehicle seat? (As the vehicle is remote controlled in this case.)

4 comments

0

You can change the CameraSubject property (Camera.CameraSubject = vehicle.Focus) or the Focus property (Camera.Focus = CFrame.new(vehicle.Focus.Position) I'm pretty sure what you're wanting to do is set the CameraSubject though.

0

I gathered that much but where to but the script and whith what activation i do not know.

1

Does the player sit in the seat? (you say it's remote-controlled.)

0

Yes, they sit in the seat and they can controll the car (seat is not attached to car) but the camera stays focused on the seat. I want it to focus on the car instead.

1 answer

✓ Accepted answer

This would require 2 scripts, a LocalScript and just a plain script.

Put the following code into a LocalScript and insert the script into game.Lighting:

local vehicle = game.Workspace.Vehicle
local camera = game.Workspace.CurrentCamera

if camera.CameraSubject == vehicle.Focus then
	camera.CameraSubject = game.Players.LocalPlayer
else
	camera.CameraSubject = vehicle.Focus
end

The following code goes in a Script

local seat = game.Workspace.Seat
local vehicle = game.Workspace.Vehicle

seat.ChildAdded:connect(function(child) -- a weld is inserted into the seat when a player sits on it
	if child:IsA("Weld") then -- check to see if the child that was inserted is a weld
		local character = child.Part1.Parent
		--local player = game.Players:GetPlayerFromCharacter(character)
		local cameraScript = game.Lighting.LocalScript:Clone()
		cameraScript.Parent = character -- insert the localscript into the character so it runs locally
		seat.ChildRemoved:wait() -- weld is removed when player stands up
		cameraScript.Disabled = true -- run script again
		cameraScript.Disabled = false
		cameraScript:Destroy()
	end
end)

Tested and it works. This code will set a players CameraSubject to a part named "Focus" in Workspace.Vehicle when they sit on the seat (Workspace.Seat) and when they stand up the CameraSubject will be reset (to the player's humanoid.)

1 comment

0

Cheers man, works a treat!

This discussion is preserved as it was. New answers, comments, and votes are closed.