DriverSeat Camera

Currently making it so when you sit in a driver seat the CameraMinZoomDistance is adjusted and when you exit the it returns to normal.

Currently I have this script and when you leave the seat it doesn’t return to normal.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local originalDistance = player.CameraMinZoomDistance

if character then
	local humanoid = character:WaitForChild("Humanoid")
	local seat = script.Parent.Parent.Parent

	local function onSeated()
		player.CameraMinZoomDistance = 25
	end
	
	local function onExit()
		player.CameraMinZoomDistance = originalDistance
	end

	humanoid.Seated:Connect(onSeated)
	seat.ChildRemoved:Connect(onExit)
end

I am not sure if you would have to use a custom camera for it or not. If you have any ideas on how to make this work, that would be appreciated.

2 Likes

Since the function connected to the event Humanoid.Seated can take an argument indicating whether the player is entering or exiting the state of sitting, we can use this argument to know which function to call.

Here’s how to fix what’s wrong with the code.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local originalDistance = player.CameraMinZoomDistance

if character then
	local humanoid = character:WaitForChild("Humanoid")
	local seat = script.Parent.Parent.Parent

	local function onSeated()
		player.CameraMinZoomDistance = 25
	end

	local function onExit()
		player.CameraMinZoomDistance = originalDistance
	end
	
	humanoid.Seated:Connect(function(active)
		if active then
			onSeated()
		else
			onExit()
		end
	end)
end

The seat variable can be removed, as it is now an unused variable.

1 Like

Still doesn’t return to the normal Camera MinZoom Distance

1 Like

You might just try this: because nothing else can sit there so it will probably be a player anyways.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local originalDistance = player.CameraMinZoomDistance

	local humanoid = character:WaitForChild("Humanoid")
	local seat = script.Parent.Parent.Parent

	local function onSeated()
		player.CameraMinZoomDistance = 25
	end

	local function onExit()
		player.CameraMinZoomDistance = originalDistance
	end

	humanoid.Seated:Connect(function(active)
		if active then
			onSeated()
		else
			onExit()
		end
	end)

1 Like

Still get the same issue where it doesn’t go back to the original distance

So it works but it doesn’t go back?

1 Like

yup that’s correct it doesn’t go back to the original distance

I mean i don’t see a issue why wouldn’t it work but you could try just to set it as a number.

local originalDistance = 0.5

This isn’t as professional but as long as it works.

1 Like

I did that however still doesn’t work. when you exit the driverseat

1 Like

I have no more ideas unless this.

humanoid.Seated:Connect(function(active)
		if active then
			onSeated()
		elseif not active then
			onExit()
		end
	end)

This is my last idea but maybe you could try occupant.Changed but i’m not sure…