It’s surprisingly easy if you do it correctly, you just detect if a player touches a part, then tween it’s camera into an anchored “camera part” to then await another touched event:
For this template example, it will be awaiting a Touched event from a part, then the player’s camera will be tweened to the part’s CFrame.
local TS = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local touchPart = workspace.TouchPart
touchPart.Touched:Connect(function(otherPart)
if player.Name == otherPart.Parent.Name then
TS:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Exponential),{CFrame = touchPart.CFrame}):Play()
end
end)
Let me know if this works.
Edit:
If you’re trying to lock the player’s camera into a part, and make the part constantly look at the player, you can simply do something like this:
local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local part = workspace.Part
RS.RenderStepped:Connect(function()
if player.Character and player.Character.HumanoidRootPart then
part.CFrame = CFrame.lookAt(part.Position,player.Character.HumanoidRootPart.Position)
camera.CFrame = part.CFrame
end
end)
I tried it and nothing happens but my game does give an output when i touch the part. ill keep trying to see if i can get it to work!
EDIT
So i tried the scripts and neither work. They both show that it is detecting me standing on it but nothing happens! maybe i just have it setup wrong? but idk.
i am getting an output error showing this " Workspace.Part.Script:9: attempt to index nil with 'Name’"
Update: i made this script but doesnt seem to work. im really bad at scripting so please bare with me!
i also tried combining the scripts you gave me to see if that would work.
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local cframe = {
["position"] = {0, 20, 0},
["orientation"] = {0, -90, 0}
}
camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Scriptable
local touchPart = workspace:WaitForChild("PartActivate")
local isTouching = false
local function lockCamera()
camera.CFrame = CFrame.new(cframe.position[1], cframe.position[2], cframe.position[3]) * CFrame.Angles(math.rad(cframe.orientation[1]), math.rad(cframe.orientation[2]), math.rad(cframe.orientation[3]))
end
lockCamera()
touchPart.Touched:Connect(function(otherPart)
if otherPart.Parent == player.Character then
isTouching = true
lockCamera()
end
end)
touchPart.TouchEnded:Connect(function(otherPart)
if otherPart.Parent == player.Character then
isTouching = false
end
end)
Ok so i kinda got it working but this really weird thing happens! when i touch the part the camera changes but my character dies for some reason and then sometimes when i respawn it will flip my character around.
heres a clip
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local triggerPart = game.Workspace:WaitForChild("TriggerPart") -- Replace "TriggerPart" with the actual name of the part you want to use as the trigger
local isLocked = false
local lockedCameraCFrame = CFrame.new(Vector3.new(0, 20, 0), Vector3.new(0, -90, 0)) -- Define the locked camera position and orientation
local function lockCamera()
isLocked = true
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = nil -- Clear the CameraSubject to stop following the character
camera.CFrame = lockedCameraCFrame -- Set the camera to the locked position and orientation
end
local function unlockCamera()
isLocked = false
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = player.Character.Humanoid
end
triggerPart.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local characterHumanoid = character and character:FindFirstChild("Humanoid")
if characterHumanoid then
lockCamera()
end
end)
triggerPart.TouchEnded:Connect(function(otherPart)
local character = otherPart.Parent
local characterHumanoid = character and character:FindFirstChild("Humanoid")
if characterHumanoid and isLocked then
unlockCamera()
end
end)
Before it would show a some sort of error thing on my screen saying “gameplay paused”
Using my script, I guess you can achieve something like this:
local partA = workspace:WaitForChild("PartA",10) --Set the two parts.
local partB = workspace:WaitForChild("PartB",10)
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local cframes = { --Customise the parts' CFrames to set the camera to.
["CFrameA"] = {
["Position"] = {0,20,0},
["Orientation"] = {0,-90,0}
},
["CFrameB"] = {
["Position"] = {0,40,0},
["Orientation"] = {0,-90,0}
},
}
camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Scriptable
partA.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChildOfClass("Humanoid") then
camera.CFrame = CFrame.new(cframes.CFrameA.Position[1],cframes.CFrameA.Position[2],cframes.CFrameA.Position[3]) * CFrame.Angles(math.rad(cframe.CFrameA.Orientation[1]),(math.rad(cframe.CFrameA.Orientation[2]),(math.rad(cframe.CFrameA.Orientation[3]))
end
end)
partB.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChildOfClass("Humanoid") then
camera.CFrame = CFrame.new(cframes.CFrameB.Position[1],cframes.CFrameB.Position[2],cframes.CFrameB.Position[3]) * CFrame.Angles(math.rad(cframe.CFrameB.Orientation[1]),(math.rad(cframe.CFrameB.Orientation[2]),(math.rad(cframe.CFrameB.Orientation[3]))
end
end)
Here’s what I use to mimic Resident Evil 1’s camera system. I used a LocalScript in StarterCharacterScripts. You can add multiple parts if you choose, and when it’s touched, it will snap to that position in a fixed mode.
task.wait(.1) -- Wait for part to load in
local pos = Vector3.new(0, 10, 0) --Position of the camera
local lookAtPos = Vector3.new(10, 0, 0) --Angle the camera is looking at
local cameraCFrame = CFrame.lookAt(pos, lookAtPos)
local camera = workspace.CurrentCamera
local camPart = workspace.CamTP --Part that changes the camera position when touched
camPart.Touched:Connect(function(hit)
camera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = cameraCFrame
end)