Im trying to make that if you go on a seat, the camera goes to part, and that works! but how to make it that if i exit the seat, the camera goes back to normal
--1
local Seat1 = game.Workspace.mailWriting1.Chair1.Seat
Seat1:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat1.Occupant ~= nil then
if game.Workspace.Houses.House1.owner.Value == Seat1.Occupant.Parent.Name then
game.Workspace.mailWriting1.Paper.SurfaceGui.TextBox.TextEditable = true
game.Workspace.mailWriting1.Paper.SurfaceGui.TextButton.Visible = true
local camera = workspace.Camera
local part = workspace.CAM1
part.Position = Vector3.new(141.345, 16.55, -102)
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
1.5, -- Length
Enum.EasingStyle.Quad, -- Easing Style
Enum.EasingDirection.Out, -- Easing Direction
0, -- Times repeated
false, -- Reverse
0 -- Delay
)
local Goals =
{
Position = Vector3.new(141.345, 13.55, -102);
}
local tween = TweenService:Create(part,Info,Goals)
tween:Play()
while true do
wait(.01)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end
end
end
end)
--2
you can add a check to see if the seat becomes unoccupied. You can use a loop with a small delay to continuously check the seat’s Occupant property. If it becomes nil , you can reset the camera’s properties back to their original values
local Seat1 = game.Workspace.mailWriting1.Chair1.Seat
local originalCameraType = Enum.CameraType.Custom -- Set the original camera type here
local originalCameraCFrame = workspace.Camera.CFrame -- Set the original camera CFrame here
Seat1:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat1.Occupant ~= nil then
if game.Workspace.Houses.House1.owner.Value == Seat1.Occupant.Parent.Name then
-- Code for when the seat is occupied
game.Workspace.mailWriting1.Paper.SurfaceGui.TextBox.TextEditable = true
game.Workspace.mailWriting1.Paper.SurfaceGui.TextButton.Visible = true
local camera = workspace.Camera
local part = workspace.CAM1
part.Position = Vector3.new(141.345, 16.55, -102)
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
1.5, -- Length
Enum.EasingStyle.Quad, -- Easing Style
Enum.EasingDirection.Out, -- Easing Direction
0, -- Times repeated
false, -- Reverse
0 -- Delay
)
local Goals = {
Position = Vector3.new(141.345, 13.55, -102);
}
local tween = TweenService:Create(part, Info, Goals)
tween:Play()
while true do
wait(0.01)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
-- Add check for seat becoming unoccupied
if Seat1.Occupant == nil then
-- Reset camera properties back to original values
camera.CameraType = originalCameraType
camera.CFrame = originalCameraCFrame
break -- Exit the loop
end
end
end
end
end)