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
LocalScripts don’t work if they are inside the Workspace. Try to use RemoteEvents in that case.
Like this:
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)
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:
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.