Camera max zoom distance not working

Hello, pretty basic stuff that everytime has a error and not at the same time since nothing on the output, this script was supposed to make the player zoom gets closer when you not in a car and zooms out when you get in the car, but it only stopped on the supposed.

local player = game.Players.LocalPlayer
local seat = script.Parent

if seat.Occupant == player.Character.Humanoid then
	player.CameraMaxZoomDistance = 27
	player.CameraMinZoomDistance = 28
else
	player.CameraMaxZoomDistance = 10
	player.CameraMinZoomDistance = 11
end
1 Like

LocalScripts don’t work if they are inside the Workspace. Try to use RemoteEvents in that case.

Like this:

remoote

Then, try to use these scripts.

Server script:

local Players = game:GetService("Players")
local seat = script.Parent
local prevOccupant = nil

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local player = nil
	if seat.Occupant then
		player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
	end
	if player then
		prevOccupant = player
		remoteEvent:FireClient(player, true)
	elseif prevOccupant then
		remoteEvent:FireClient(prevOccupant, false)
	end
end)

Local script: (Put it within the StarterPlayerScripts)

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

remoteEvent.OnClientEvent:Connect(function(seated)
	if seated then
		player.CameraMaxZoomDistance = 27
		player.CameraMinZoomDistance = 28
	else
		player.CameraMaxZoomDistance = 10
		player.CameraMinZoomDistance = 11
	end
end)

I just edited it

5 Likes

i tried that and didnt work lol

Is any of that scripts erroring?

image
image
image
and none of them are erroring

seat.Occupant is a Humanoid Value, you’re just attempting to find the Humanoid itself alone which is why the conditional check isn’t working so do change it to seat.Occupant.Parent to get the Character’s Model (Also you spelled it as “Ocuppant”)

Also please don’t create duplicate topics, stick with your original one:

I just edited it. Sorry, I didn’t notice.

Just edited my post. Try again, please.

and that worked! no possible infinite yield and the camera zooms in and out, really appreciated!

What is the point of using a RemoteEvent and a ServerScript? There is no security involved in this so there is no reason to using server scripts. A better idea would be to make a LocalScript in StarterCharacterScripts that checks when the Humanoid’s Sit value changes. Check if SeatPart is a vehicle seat or has a specific name. Then change the zoom distance from there.

1 Like