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

Change CameraMinZoomDistance when sitting in VehicleSeat???

So i have scripted a car, it works fine and so! But the only thing is that the car is a mesh so in first person it look really silly... I wanna script so when a player sits in the car the CameraMinZoomDistance is 20.

I thaught of occupant as a good thing to use, but i don't know how to access a players CameraMinZoomDistance via a script in the VehicleSeat..

Can somebody help me?

Here is the script:

local Seat =  script.Parent -- Path to seat

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		local Char = Seat.Occupant.Parent
		
	end
end)

1 answer

CameraMinZoomDistance is a property of Player. So you need to obtain the player from the character using the GetPlayerFromCharacter() function.

local Seat =  script.Parent -- Path to seat
local player

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if Seat.Occupant ~= nil then
		local Char = Seat.Occupant.Parent
		player = game:GetService("Players"):GetPlayerFromCharacter(Char)
		player.CameraMinZoomDistance =  -- new value
	else
		player.CameraMinZoomDistance = -- old value
	end
end)

7 comments

0

Yo it is, dope.

0

where is the script gonna be, and is it local script or server script?

0

LocalScript in StarterCharacterScripts works

0

Actually don't do that. Script in ServerScriptService. People can exploit local scripts or whatever.

0

ok!

0

is there anyway to make the camera go back to normal when player has left the seat?

0

Yes, I'll edit that into the post. Also, you should make the server script inside each seat if you plan on having multiple. It was late when I commented so I wasn't really thinking

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