Hello, i made a pretty basic script so when you not in a car your camera is closer and when you enter the vehicle the camera zooms out (max zoom distance), but for some reason is not working!!! (not a surprise lol)
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 can’t run if they’re parented inside the workspace, what you could probably do instead is use RemoteEvents to check if the Player’s Humanoid is valid to seat.Occupant, and changing the Camera’s ZoomDistances from the client side that way
local Player
local seat = script.Parent
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant ~= nil then
local Character = seat.Occupant.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
if Player then
Event:FireClient(Player, true)
end
else
Event:FireClient(Player, false)
end
end)
--Client Side, located inside StarterPlayerScripts
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
Event.OnClientEvent:Connect(function(Seated)
if Seated then
player.CameraMaxZoomDistance = 27
player.CameraMinZoomDistance = 28
else
player.CameraMaxZoomDistance = 10
player.CameraMinZoomDistance = 11
end
end)
print("Script running")
local Player
local seat = script.Parent
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
print("Event fired")
if seat.Occupant ~= nil then
local Character = seat.Occupant.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
if Player then
print("Firing Remote to true")
Event:FireClient(Player, true)
end
else
print("Firing Remote to false")
Event:FireClient(Player, false)
end
end)
--Client Side, located inside StarterPlayerScripts
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
Event.OnClientEvent:Connect(function(Seated)
print("Event received, result:", Seated)
if Seated then
player.CameraMaxZoomDistance = 27
player.CameraMinZoomDistance = 28
else
player.CameraMaxZoomDistance = 10
player.CameraMinZoomDistance = 11
end
end)
The only thing I see then is that you didn’t either parent this the right way or it’s a Server Script, if you haven’t done so already change it to a LocalScript , and parent it inside StarterPlayerScripts
print("Script running")
local Player
local seat = script.Parent
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
print("Event fired")
if seat.Occupant ~= nil then
local Character = seat.Occupant.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
print("Current Player:", Player)
if Player then
print("Firing Remote to true")
Event:FireClient(Player, true)
print("Test")
end
else
print("Firing Remote to false")
Event:FireClient(Player, false)
print("Test")
end
end)
print("Script running")
local Player
local seat = script.Parent
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
print("Event fired")
if seat.Occupant ~= nil then
local Character = seat.Occupant.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
print("Current Player:", Player)
if Player then
Player.CameraMaxZoomDistance = 27
Player.CameraMinZoomDistance = 28
--print("Firing Remote to true")
--Event:FireClient(Player, true)
print("Test")
end
else
Player.CameraMaxZoomDistance = 10
Player.CameraMinZoomDistance = 11
--print("Firing Remote to false")
--Event:FireClient(Player, false)
print("Test")
end
end)