You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make if the player is going into a vehicle seat, the camera is locking into Attach mode.
What is the issue? Include screenshots / videos if possible!
When I go into the car, it prints out what I want. But the camera is not changing at all.
local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.Camera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
Camera.CameraType = "Attach"
print("joined seat")
else
Camera.CameraType = "Custom"
warn("left seat")
end
end)
local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
CurrentCamera.CameraType = Enum.CameraType.Attach
print("joined seat")
else
CurrentCamera.CameraType = Enum.CameraType.Custom
warn("left seat")
end
end)
local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
game:GetService('RunService').Stepped:Connect(function()
Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10) -- change the numbers
end)
game.Workspace.CurrentCamera.CameraType= "Attach"
print("joined seat")
else
game.Workspace.CurrentCamera.CameraType= "Custom"
warn("left seat")
end
end)
yes but you need to position the camera behind the player. I suggest using another part instead of humanoid though you would need to rotate the part till the camera goes behind the player
local seat = game.Workspace.Car.VehicleSeat
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
game.Workspace.CurrentCamera.CameraType= "Attach"
print("joined seat")
Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10)
else
game.Workspace.CurrentCamera.CameraType= "Custom"
warn("left seat")
end
end)
-- [[ use 'workspace' not 'game.Workspace' since the 'workspace' one is a global variable. ]]
local seat = workspace:WaitForChild("Car"):FindFirstChild("VehicleSeat")
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
game:GetService('RunService').Stepped:Connect(function()
Camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,10) -- change the numbers
end)
workspace.CurrentCamera.CameraType = Enum.CameraType.Attach
print("joined seat")
else
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
warn("left seat")
end
end)
This is a Pseudo Code so I’m not sure that this will work but try it out.
local seat = workspace.Car.VehicleSeat
local Camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
Camera.CameraType = Enum.CameraType.Attach
print("joined seat")
else
Camera.CameraType = Enum.CameraType.Custom
warn("left seat")
end
end)
local Seat = game.Workspace.Car:WaitForChild("VehicleSeat")
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Humanoid = Seat.Occupant
if Humanoid then
Camera.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService").Stepped:Connect(function()
Camera.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position)
Camera.CameraSubject = Player.Character.HumanoidRootPart
end)
else
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
end
end)
That should work,
Make sure this is a LocalScript!
workspace.CurrentCamera in a server script creates a reference to the server’s camera, not a player’s camera, you’ll need a RemoteEvent which fires some client (the occupant of the seat) and then you can manipulate their camera locally.
Also “game.Players.LocalPlayer” isn’t defined in server scripts.
The reason this script isn’t working as a local script is because the “Occupant” property shared by “Seat” and “VehicleSeat” instances doesn’t replicate to the server.